Class: Orchestra::Node::InlineNode

Inherits:
Orchestra::Node show all
Defined in:
lib/orchestra/node.rb

Defined Under Namespace

Classes: ExecutionContext

Instance Attribute Summary collapse

Attributes inherited from Orchestra::Node

#collection, #dependencies, #provisions

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Orchestra::Node

#collection?, #perform, #process, #required_dependencies

Constructor Details

#initialize(args = {}) ⇒ InlineNode

Returns a new instance of InlineNode.



65
66
67
68
69
70
71
72
# File 'lib/orchestra/node.rb', line 65

def initialize args = {}
  @defaults = args.delete :defaults do {} end
  @perform_block = args.fetch :perform_block
  args.delete :perform_block
  super args
  @context_class = build_execution_context_class
  validate!
end

Instance Attribute Details

#context_classObject (readonly)

Returns the value of attribute context_class.



63
64
65
# File 'lib/orchestra/node.rb', line 63

def context_class
  @context_class
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



63
64
65
# File 'lib/orchestra/node.rb', line 63

def defaults
  @defaults
end

#perform_blockObject (readonly)

Returns the value of attribute perform_block.



63
64
65
# File 'lib/orchestra/node.rb', line 63

def perform_block
  @perform_block
end

Class Method Details

.build(&block) ⇒ Object



57
58
59
60
61
# File 'lib/orchestra/node.rb', line 57

def self.build &block
  builder = DSL::Nodes::Builder.new
  DSL::Nodes::Context.evaluate builder, &block
  builder.build_node
end

Instance Method Details

#apply_defaults(input) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/orchestra/node.rb', line 94

def apply_defaults input
  defaults.each do |key, thunk|
    next if input.has_key? key
    input[key] = thunk.call
  end
  input
end

#build_context(input) ⇒ Object



89
90
91
92
# File 'lib/orchestra/node.rb', line 89

def build_context input
  state = apply_defaults input
  execution_context = context_class.new state, perform_block
end

#build_execution_context_classObject



80
81
82
83
84
85
86
87
# File 'lib/orchestra/node.rb', line 80

def build_execution_context_class
  context = Class.new ExecutionContext
  context.class_exec dependencies, collection do |deps, collection|
    deps.each do |dep| define_dependency dep end
    alias_method :fetch_collection, collection if collection
  end
  context
end

#optional_dependenciesObject



102
103
104
# File 'lib/orchestra/node.rb', line 102

def optional_dependencies
  defaults.keys
end

#validate!Object



74
75
76
77
78
# File 'lib/orchestra/node.rb', line 74

def validate!
  unless perform_block
    raise ArgumentError, "expected inline node to define a perform block"
  end
end