Sha256: 7c68a64332842cadc5116d8c8f21f6099d8d87869e92c007b7c48f03762af4d0

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require 'docman/commands/command'

module Docman
  module Builders
    class Builder < Docman::Command
      @@builders = {}
      @@build_results = {}


      def self.create(params = nil, context = nil, caller = nil)
        c = @@builders[params['handler']]
        if c
          c.new(params, context, caller, 'builder')
        else
          raise "Bad builder type: #{type}"
        end
      end

      def self.register_builder(name)
        @@builders[name] = self
      end

      def config
        super
        @version = nil
        environment = Application.instance.environment(@context.environment_name)
        clean_changed = environment['clean_changed'].nil? ? true : environment['clean_changed']
        add_action('before_execute', {'type' => :clean_changed}, @context) if clean_changed
      end

      def validate_command
        raise "Please provide 'context'" if @context.nil?
        raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
      end

      def version
        @version
      end

      before_execute do
        if @context.need_rebuild?
          @context.build_mode = :rebuild
        else
          if @context.changed? or changed?
            @context.build_mode = :update
            log("Changed")
          else
            log("Not changed")
            @context.build_mode = :none
            raise NoChangesError, 'This version already deployed'
          end
        end

      end

      after_execute do
        if @execute_result
          @execute_result = @context.write_info(@execute_result)
        end
      end

      def changed?
        false
      end

      def describe
        "Build: #{properties_info}"
      end

      def prefix
        "#{@context['name']} - #{self.class.name}"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
docman-0.0.46 lib/docman/builders/builder.rb
docman-0.0.45 lib/docman/builders/builder.rb
docman-0.0.44 lib/docman/builders/builder.rb