Class: StepMachine::Step
- Inherits:
-
Object
- Object
- StepMachine::Step
- Defined in:
- lib/step_machine/step.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#condition_block ⇒ Object
readonly
Returns the value of attribute condition_block.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#next_step(&block) ⇒ Object
Returns the value of attribute next_step.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#validation ⇒ Object
readonly
Returns the value of attribute validation.
Instance Method Summary collapse
- #condition(&block) ⇒ Object
- #errors(init_error = nil) ⇒ Object
-
#initialize(name) ⇒ Step
constructor
A new instance of Step.
- #next ⇒ Object
- #perform ⇒ Object
- #performed? ⇒ Boolean
- #success(&block) ⇒ Object
- #validate(value = nil, &block) ⇒ Object
Constructor Details
#initialize(name) ⇒ Step
Returns a new instance of Step.
8 9 10 |
# File 'lib/step_machine/step.rb', line 8 def initialize(name) self.name = name end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/step_machine/step.rb', line 5 def block @block end |
#condition_block ⇒ Object (readonly)
Returns the value of attribute condition_block.
6 7 8 |
# File 'lib/step_machine/step.rb', line 6 def condition_block @condition_block end |
#exception ⇒ Object
Returns the value of attribute exception.
5 6 7 |
# File 'lib/step_machine/step.rb', line 5 def exception @exception end |
#group ⇒ Object
Returns the value of attribute group.
5 6 7 |
# File 'lib/step_machine/step.rb', line 5 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/step_machine/step.rb', line 5 def name @name end |
#next_step(&block) ⇒ Object
Returns the value of attribute next_step.
5 6 7 |
# File 'lib/step_machine/step.rb', line 5 def next_step @next_step end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/step_machine/step.rb', line 6 def result @result end |
#validation ⇒ Object (readonly)
Returns the value of attribute validation.
6 7 8 |
# File 'lib/step_machine/step.rb', line 6 def validation @validation end |
Instance Method Details
#condition(&block) ⇒ Object
33 34 35 36 |
# File 'lib/step_machine/step.rb', line 33 def condition(&block) @condition_block = block if block self end |
#errors(init_error = nil) ⇒ Object
17 18 19 20 21 |
# 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 ⇒ Object
38 39 40 41 |
# 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 ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# 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? ⇒ Boolean
55 56 57 |
# File 'lib/step_machine/step.rb', line 55 def performed? !!@performed end |
#success(&block) ⇒ Object
23 24 25 26 |
# File 'lib/step_machine/step.rb', line 23 def success(&block) @success = block self end |
#validate(value = nil, &block) ⇒ Object
12 13 14 15 |
# File 'lib/step_machine/step.rb', line 12 def validate(value = nil, &block) @validation = block || value self end |