Sha256: 55cf3caecf792421190bb46ee4fa05c961bf34860ca4036d5db2c6898978bb98

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

module Orchestra
  module DSL
    module Steps
      class Builder
        attr_accessor :collection, :execute_block

        attr :defaults, :dependencies, :provisions

        def initialize
          @defaults = {}
          @dependencies = []
          @provisions = []
        end

        def build_step
          Step::InlineStep.new(
            :collection    => collection,
            :defaults      => defaults,
            :dependencies  => dependencies,
            :execute_block => execute_block,
            :provides      => provisions,
          )
        end
      end

      class Context < BasicObject
        def self.evaluate builder, &block
          context = new builder
          context.instance_eval &block
        end

        def initialize builder
          @builder = builder
        end

        def depends_on *dependencies
          defaults, dependencies = Util.extract_hash dependencies
          @builder.dependencies.concat dependencies
          defaults.each do |key, default|
            @builder.dependencies << key
            @builder.defaults[key] = Util.to_lazy_thunk default
          end
        end

        def modifies provision, args = {}
          collection, _ = Util.extract_key_args args, :collection => false
          if collection
            iterates_over provision
          else
            depends_on provision
          end
          provides provision
        end

        def provides *provisions
          @builder.provisions.concat provisions
        end

        def execute &block
          @builder.execute_block = block
        end

        def iterates_over dependency
          @builder.dependencies << dependency
          @builder.collection = dependency
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ntl-orchestra-0.9.5 lib/orchestra/dsl/steps.rb
ntl-orchestra-0.9.4 lib/orchestra/dsl/steps.rb
ntl-orchestra-0.9.3 lib/orchestra/dsl/steps.rb