class SmashTheState::Operation::ValidationStep

Attributes

implementations[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/smash_the_state/operation/validation_step.rb, line 6
def initialize(options = {})
  @name            = :validate
  @implementations = []
  @options         = {
    side_effect_free: true
  }.merge(options)
end

Public Instance Methods

add_implementation(&block) click to toggle source
# File lib/smash_the_state/operation/validation_step.rb, line 14
def add_implementation(&block)
  tap do
    @implementations << block
  end
end
dup() click to toggle source
Calls superclass method SmashTheState::Operation::Step#dup
# File lib/smash_the_state/operation/validation_step.rb, line 38
def dup
  # it's not enough to duplicate the step, we should also duplicate our
  # implementations. otherwise the list of implementations will be shared
  super.tap do |s|
    s.implementations = s.implementations.dup
  end
end
implementation() click to toggle source
# File lib/smash_the_state/operation/validation_step.rb, line 20
def implementation
  blocks = @implementations

  proc do
    # self here should be a state
    blocks.reduce(self) do |memo, i|
      memo.class_eval(&i)
    end
  end
end
validate!(state) click to toggle source
# File lib/smash_the_state/operation/validation_step.rb, line 31
def validate!(state)
  state.tap do
    SmashTheState::Operation::State.
      eval_validation_directives_block(state, &implementation)
  end
end