Class: Orchestra::Step::InlineStep

Inherits:
Orchestra::Step show all
Defined in:
lib/orchestra/step.rb

Defined Under Namespace

Classes: InlineContext

Instance Attribute Summary collapse

Attributes inherited from Orchestra::Step

#collection, #dependencies, #provisions

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Orchestra::Step

#collection?, #execute, #process, #required_dependencies

Constructor Details

#initialize(args = {}) ⇒ InlineStep

Returns a new instance of InlineStep.



62
63
64
65
66
67
68
69
# File 'lib/orchestra/step.rb', line 62

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

Instance Attribute Details

#context_classObject (readonly)

Returns the value of attribute context_class.



60
61
62
# File 'lib/orchestra/step.rb', line 60

def context_class
  @context_class
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



60
61
62
# File 'lib/orchestra/step.rb', line 60

def defaults
  @defaults
end

#execute_blockObject (readonly)

Returns the value of attribute execute_block.



60
61
62
# File 'lib/orchestra/step.rb', line 60

def execute_block
  @execute_block
end

Class Method Details

.build(&block) ⇒ Object



54
55
56
57
58
# File 'lib/orchestra/step.rb', line 54

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

Instance Method Details

#apply_defaults(input) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/orchestra/step.rb', line 91

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



86
87
88
89
# File 'lib/orchestra/step.rb', line 86

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

#build_execution_context_classObject



77
78
79
80
81
82
83
84
# File 'lib/orchestra/step.rb', line 77

def build_execution_context_class
  context = Class.new InlineContext
  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



99
100
101
# File 'lib/orchestra/step.rb', line 99

def optional_dependencies
  defaults.keys
end

#validate!Object



71
72
73
74
75
# File 'lib/orchestra/step.rb', line 71

def validate!
  unless execute_block
    raise ArgumentError, "expected inline step to define a execute block"
  end
end