Class: Journea::StateMachine
- Inherits:
-
Object
- Object
- Journea::StateMachine
- Includes:
- Statesman::Machine
- Defined in:
- lib/journea/state_machine.rb
Class Method Summary collapse
Instance Method Summary collapse
- #in_initial_state? ⇒ Boolean
- #next_step ⇒ Object
- #previous_step ⇒ Object
- #transition_to_next_step ⇒ Object
-
#validate_transition(options = { from: nil, to: nil, metadata: nil }) ⇒ Object
Monkey patch to prevent hard fail on transitioning between unsupported routes.
Class Method Details
.step(*args) ⇒ Object
5 6 7 8 |
# File 'lib/journea/state_machine.rb', line 5 def self.step(*args) # Instead of using Statesman 'state', this let's us use 'step' state(*args) end |
Instance Method Details
#in_initial_state? ⇒ Boolean
24 25 26 |
# File 'lib/journea/state_machine.rb', line 24 def in_initial_state? current_state end |
#next_step ⇒ Object
15 16 17 18 |
# File 'lib/journea/state_machine.rb', line 15 def next_step raise "No next step defined" if allowed_transitions.empty? allowed_transitions.first.to_sym end |
#previous_step ⇒ Object
10 11 12 13 |
# File 'lib/journea/state_machine.rb', line 10 def previous_step return nil unless last_transition.present? last_transition.["previous_state"] end |
#transition_to_next_step ⇒ Object
20 21 22 |
# File 'lib/journea/state_machine.rb', line 20 def transition_to_next_step transition_to!(next_step, previous_state: current_state) end |
#validate_transition(options = { from: nil, to: nil, metadata: nil }) ⇒ Object
Monkey patch to prevent hard fail on transitioning between unsupported routes
29 30 31 32 33 34 35 36 37 |
# File 'lib/journea/state_machine.rb', line 29 def validate_transition( = { from: nil, to: nil, metadata: nil }) from = to_s_or_nil([:from]) to = to_s_or_nil([:to]) # Call all guards, they raise exceptions if they fail guards_for(from: from, to: to).each do |guard| guard.call(@object, last_transition, [:metadata]) end end |