Sha256: d1000033ea2f837496892bac5838b9865e87b2a8dc08482ff51229cc3813eb0f

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module Borg
  class Configuration < Capistrano::Configuration
    module Stages
      def stage(app, name, &block)
        app = app.to_sym
        name = name.to_sym
        application app unless @applications[app]

        namespace app do
          desc "Load Application #{app} and Stage #{name}"
          task name do
            @applications[app].stages[name].execute
          end
        end
        @applications[app].stages[name] ||= Stage.new(name, @applications[app])
        @applications[app].stages[name].execution_blocks << block if block_given?
      end

      class Stage
        attr_accessor :execution_blocks
        attr_accessor :parent

        # TODO: We might want to name this differently
        def name
          "#{parent.name}:#{@name}"
        end

        def initialize(name, parent)
          @execution_blocks = []
          @name = name
          @parent = parent
        end

        def load_into(config)
          if config.respond_to?(:stage)
            # Undefine the stage method now that the app:stage config is created
            config_metaclass = class << config; self; end
            config_metaclass.send(:undef_method, 'stage')

            # Create a capistrano variable for stage
            config.instance_exec(@name, &(lambda { |name| set :stage, name }))
          end

          parent.load_into(config)
          @execution_blocks.each { |blk| config.load(&blk) }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
borg-rb-0.1.5 lib/borg/configuration/stages.rb
borg-rb-0.1.4 lib/borg/configuration/stages.rb
borg-rb-0.1.0 lib/borg/configuration/stages.rb