Class: SmashTheState::Operation::DryRun::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/smash_the_state/operation/dry_run.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wet_sequence) ⇒ Builder

Returns a new instance of Builder.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/smash_the_state/operation/dry_run.rb', line 7

def initialize(wet_sequence)
  @wet_sequence = wet_sequence
  @dry_sequence = Operation::Sequence.new

  # in the case of a dynamic schema, front-load it as the first step
  dynamic_schema_step = @wet_sequence.dynamic_schema_step

  return if dynamic_schema_step.nil?

  step(dynamic_schema_step.name, &dynamic_schema_step.implementation)
end

Instance Attribute Details

#dry_sequenceObject (readonly)

Returns the value of attribute dry_sequence.



5
6
7
# File 'lib/smash_the_state/operation/dry_run.rb', line 5

def dry_sequence
  @dry_sequence
end

#wet_sequenceObject (readonly)

Returns the value of attribute wet_sequence.



5
6
7
# File 'lib/smash_the_state/operation/dry_run.rb', line 5

def wet_sequence
  @wet_sequence
end

Instance Method Details

#step(step_name, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smash_the_state/operation/dry_run.rb', line 19

def step(step_name, &block)
  referenced_steps = wet_sequence.steps_for_name(step_name)

  if block
    add_dry_run_step(step_name, &block)
    return
  end

  if referenced_steps.empty?
    raise "dry run sequence referred to unknown step " \
          "#{step_name.inspect}. make sure to define " \
          "your dry run sequence last, after all your steps are defined"
  end

  referenced_steps.each do |referenced_step|
    # we're gonna copy the implementation verbatim but add a new step marked as
    # side-effect-free, because if the step was added to the dry run sequence it
    # must be assumed to be side-effect-free
    add_dry_run_step(step_name, &referenced_step.implementation)
  end
end