class StepMachine::Step
Attributes
block[RW]
condition_block[R]
exception[RW]
group[RW]
name[RW]
next_step[RW]
result[R]
validation[R]
Public Class Methods
new(name)
click to toggle source
# File lib/step_machine/step.rb, line 8 def initialize(name) self.name = name end
Public Instance Methods
condition(&block)
click to toggle source
# File lib/step_machine/step.rb, line 33 def condition(&block) @condition_block = block if block self end
errors(init_error = nil)
click to toggle source
# File lib/step_machine/step.rb, line 17 def errors(init_error = nil) @errors = init_error if (!init_error.nil? and init_error.class != @errors.class) @errors = [] if (init_error.nil? && @errors.nil?) @errors end
next()
click to toggle source
# File lib/step_machine/step.rb, line 38 def next return next_step.call(self) if next_step.is_a?(Proc) next_step end
perform()
click to toggle source
# File lib/step_machine/step.rb, line 43 def perform return true unless condition_satisfied @performed = true @result = block.call(self) valid = valid? @success.call(self) if @success && valid valid rescue => e @exception = e false end
performed?()
click to toggle source
# File lib/step_machine/step.rb, line 55 def performed? !!@performed end
success(&block)
click to toggle source
# File lib/step_machine/step.rb, line 23 def success(&block) @success = block self end
validate(value = nil, &block)
click to toggle source
# File lib/step_machine/step.rb, line 12 def validate(value = nil, &block) @validation = block || value self end
Private Instance Methods
condition_satisfied()
click to toggle source
# File lib/step_machine/step.rb, line 71 def condition_satisfied return false if (group && group.condition_block && !group.condition_block.call) return false if (condition_block && !condition_block.call) true end
valid?()
click to toggle source
# File lib/step_machine/step.rb, line 61 def valid? if validation return (!(validation.call(self) === false) && errors.empty?) if validation.is_a?(Proc) return false unless errors.empty? return result.match(validation) if validation.is_a?(Regexp) return validation == result end true end