Module: SmashTheState::Operation::DryRun

Included in:
SmashTheState::Operation
Defined in:
lib/smash_the_state/operation/dry_run.rb

Defined Under Namespace

Classes: Builder

Instance Method Summary collapse

Instance Method Details

#dry_run(params = {}) ⇒ Object Also known as: dry_call

dry runs are meant to produce the same types of output as a normal call/run, except they should not produce any side-effects (writing to a database, etc)



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/smash_the_state/operation/dry_run.rb', line 54

def dry_run(params = {})
  # if an valid dry run sequence has been specified, use it. otherwise run the main
  # sequence in "side-effect free mode" (filtering out steps that cause
  # side-effects)
  seq = if dry_run_sequence?
          dry_run_sequence
        else
          sequence.side_effect_free
        end

  run_sequence(seq, params)
end

#dry_run_sequence(&block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/smash_the_state/operation/dry_run.rb', line 68

def dry_run_sequence(&block)
  # to keep the operation code cleaner, we will delegate dry run sequence building
  # to another module (allows us to have a method named :step without having to make
  # the operation :step method super complicated)
  @dry_run_builder ||= DryRun::Builder.new(sequence)

  # if a block is given, we want to evaluate it with the builder
  @dry_run_builder.instance_eval(&block) if block_given?

  # the builder will produce a side-effect-free sequence for us
  @dry_run_builder.dry_sequence
end

#dry_run_sequence?Boolean

a valid dry run sequence should have at least one step. if there isn’t at least one step, the dry run sequence is basically a no-op

Returns:

  • (Boolean)


83
84
85
# File 'lib/smash_the_state/operation/dry_run.rb', line 83

def dry_run_sequence?
  !dry_run_sequence.steps.empty?
end