Class: InterstateMachine::StateMachine
- Inherits:
-
Object
- Object
- InterstateMachine::StateMachine
- Defined in:
- lib/interstate_machine/state_machine.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#state ⇒ Object
Returns the value of attribute state.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #evaluate_transition_by!(rule) ⇒ Object
-
#initialize(object) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #next ⇒ Object
- #next_state ⇒ Object
Constructor Details
#initialize(object) ⇒ StateMachine
Returns a new instance of StateMachine.
6 7 8 9 |
# File 'lib/interstate_machine/state_machine.rb', line 6 def initialize(object) @states = object.class.machine_states @state = defined_state(object) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/interstate_machine/state_machine.rb', line 3 def context @context end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/interstate_machine/state_machine.rb', line 4 def state @state end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
3 4 5 |
# File 'lib/interstate_machine/state_machine.rb', line 3 def states @states end |
Instance Method Details
#evaluate_transition_by!(rule) ⇒ Object
11 12 13 14 |
# File 'lib/interstate_machine/state_machine.rb', line 11 def evaluate_transition_by!(rule) @context = rule raise failed_transition unless context.from.include? context.object.state.to_sym end |
#next ⇒ Object
20 21 22 23 |
# File 'lib/interstate_machine/state_machine.rb', line 20 def next context.object.state = context.transition_to.first context.object.save end |
#next_state ⇒ Object
16 17 18 |
# File 'lib/interstate_machine/state_machine.rb', line 16 def next_state context.transition_to.first end |