Class: Hifsm::Machine
- Inherits:
-
Object
- Object
- Hifsm::Machine
- Defined in:
- lib/hifsm/machine.rb
Overview
This is just a storage of current state
Instance Method Summary collapse
-
#act!(*args) ⇒ Object
Public API.
-
#all_states ⇒ Object
internals.
- #fire(event, *args) ⇒ Object
-
#initialize(fsm, target, initial_state = nil) ⇒ Machine
constructor
A new instance of Machine.
- #state ⇒ Object
- #states ⇒ Object
- #to_s ⇒ Object
- #valid_events(*args) ⇒ Object
Constructor Details
#initialize(fsm, target, initial_state = nil) ⇒ Machine
Returns a new instance of Machine.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/hifsm/machine.rb', line 4 def initialize(fsm, target, initial_state = nil) @target = target || self @fsm = fsm initial_state_method_name = "initial_#{fsm.name}" initial_state ||= target.send(initial_state_method_name) if target.respond_to?(initial_state_method_name) initial_state &&= fsm.get_state!(initial_state) initial_state ||= fsm.initial_state! @state = initial_state.enter! end |
Instance Method Details
#act!(*args) ⇒ Object
Public API
18 19 20 |
# File 'lib/hifsm/machine.rb', line 18 def act!(*args) @state.act!(@target, *args) end |
#all_states ⇒ Object
internals
39 40 41 |
# File 'lib/hifsm/machine.rb', line 39 def all_states @fsm.all_states.reject(&:sub_fsm).collect(&:to_s) end |
#fire(event, *args) ⇒ Object
43 44 45 46 47 |
# File 'lib/hifsm/machine.rb', line 43 def fire(event, *args) @state.fire(@target, event, *args) do |new_state| @state = new_state end end |
#state ⇒ Object
22 23 24 |
# File 'lib/hifsm/machine.rb', line 22 def state @state end |
#states ⇒ Object
30 31 32 |
# File 'lib/hifsm/machine.rb', line 30 def states @fsm.states end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/hifsm/machine.rb', line 34 def to_s @state.to_s end |
#valid_events(*args) ⇒ Object
26 27 28 |
# File 'lib/hifsm/machine.rb', line 26 def valid_events(*args) @state.valid_events(@target, *args) end |