Sha256: d54384db746149ef3a65f5fa1885d003f9f55d93ebb80efbc4fb8f76cde4781b

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

module Orchestra
  module DSL
    module Nodes
      class Builder
        attr_accessor :collection, :perform_block

        attr :defaults, :dependencies, :provisions

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

        def build_node
          Node::InlineNode.new(
            :collection    => collection,
            :defaults      => defaults,
            :dependencies  => dependencies,
            :perform_block => perform_block,
            :provides      => provisions,
          )
        end
      end

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

        attr :collection, :perform

        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 perform &block
          @builder.perform_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.2 lib/orchestra/dsl/nodes.rb
ntl-orchestra-0.9.1 lib/orchestra/dsl/nodes.rb
ntl-orchestra-0.9.0 lib/orchestra/dsl/nodes.rb