Class: Dotpretty::StateMachine
- Inherits:
-
Object
- Object
- Dotpretty::StateMachine
- Defined in:
- lib/dotpretty/state_machine.rb
Instance Attribute Summary collapse
-
#current_state_name ⇒ Object
readonly
Returns the value of attribute current_state_name.
Instance Method Summary collapse
-
#initialize(initial_state:, observer:, states:) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #trigger(event, *args) ⇒ Object
Constructor Details
#initialize(initial_state:, observer:, states:) ⇒ StateMachine
Returns a new instance of StateMachine.
6 7 8 9 10 |
# File 'lib/dotpretty/state_machine.rb', line 6 def initialize(initial_state:, observer:, states:) self.current_state_name = initial_state self.observer = observer self.states = states end |
Instance Attribute Details
#current_state_name ⇒ Object
Returns the value of attribute current_state_name.
12 13 14 |
# File 'lib/dotpretty/state_machine.rb', line 12 def current_state_name @current_state_name end |
Instance Method Details
#trigger(event, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dotpretty/state_machine.rb', line 14 def trigger(event, *args) current_state.trigger(event) do |transition, exit_action| perform(exit_action, *args) if current_state_name != transition[:next_state_name] perform(transition[:action], *args) if current_state_name != transition[:next_state_name] self.current_state_name = transition[:next_state_name] perform(current_state.entry_action, *args) end end end |