Module: InterstateMachine::ClassMethods
- Defined in:
- lib/interstate_machine.rb
Instance Method Summary collapse
- #allow(event: nil, transition_to: nil, from: nil) ⇒ Object
- #initial_state(state) ⇒ Object
- #initialized_state ⇒ Object
- #machine_states ⇒ Object
- #on(event:, transition_to: nil, from: nil) {|event| ... } ⇒ Object
- #transition_table(*states) ⇒ Object
Instance Method Details
#allow(event: nil, transition_to: nil, from: nil) ⇒ Object
49 50 51 52 53 |
# File 'lib/interstate_machine.rb', line 49 def allow(event: nil, transition_to: nil, from: nil) define_method "#{event}_#{from.first}" do ensure_can_transit(event, transition_to, from, multiple: true) end end |
#initial_state(state) ⇒ Object
23 24 25 |
# File 'lib/interstate_machine.rb', line 23 def initial_state(state) @initialized_state = state end |
#initialized_state ⇒ Object
27 28 29 |
# File 'lib/interstate_machine.rb', line 27 def initialized_state @initialized_state ||= [] end |
#machine_states ⇒ Object
31 32 33 |
# File 'lib/interstate_machine.rb', line 31 def machine_states @machine_states ||= [] end |
#on(event:, transition_to: nil, from: nil) {|event| ... } ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/interstate_machine.rb', line 40 def on(event:, transition_to: nil, from: nil) yield(event) if block_given? perform_transition_by( event: event, transition_to: transition_to, from: from ) end |
#transition_table(*states) ⇒ Object
35 36 37 38 |
# File 'lib/interstate_machine.rb', line 35 def transition_table(*states) @machine_states = states yield end |