Class: Porch::StepChain

Inherits:
Object
  • Object
show all
Defined in:
lib/porch/step_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organizer) ⇒ StepChain

Returns a new instance of StepChain.



5
6
7
8
# File 'lib/porch/step_chain.rb', line 5

def initialize(organizer)
  @organizer = organizer
  @steps = []
end

Instance Attribute Details

#organizerObject (readonly)

Returns the value of attribute organizer.



3
4
5
# File 'lib/porch/step_chain.rb', line 3

def organizer
  @organizer
end

#stepsObject (readonly)

Returns the value of attribute steps.



3
4
5
# File 'lib/porch/step_chain.rb', line 3

def steps
  @steps
end

Instance Method Details

#add(step = nil, &block) ⇒ Object



10
11
12
13
# File 'lib/porch/step_chain.rb', line 10

def add(step=nil, &block)
  step = block if block_given?
  steps << ExecutableStepDecorator.new(step, organizer)
end

#execute(context) ⇒ Object



24
25
26
27
28
29
# File 'lib/porch/step_chain.rb', line 24

def execute(context)
  ctx = Context.new context
  steps.map do |step|
    ctx = step.execute ctx unless ctx.stop_processing?
  end.last || ctx
end

#insert(index, step = nil, &block) ⇒ Object



15
16
17
18
# File 'lib/porch/step_chain.rb', line 15

def insert(index, step=nil, &block)
  step = block if block_given?
  steps.insert index, ExecutableStepDecorator.new(step, organizer)
end

#remove(step) ⇒ Object



20
21
22
# File 'lib/porch/step_chain.rb', line 20

def remove(step)
  @steps.delete_if { |decorated_step| decorated_step.step == step }
end