Module: EdgeStateMachine::InstanceMethods
- Defined in:
- lib/edge-state-machine.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #current_state_name(name = :default) ⇒ Object
- #fire_event(name = :default, options = {}, event_name) ⇒ Object
- #initial_state_name(name = :default) ⇒ Object
- #set_current_state(new_state, machine_name = :default, options = {}) ⇒ Object
Instance Attribute Details
#current_state(name = :default) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/edge-state-machine.rb', line 63 def current_state(name = :default) @current_states ||= {} machine = self.class.state_machines[name] if (respond_to? :load_from_persistence) @current_states[name] ||= self.class.state_machines[name].states[load_from_persistence(name).to_sym] end @current_states[name] ||= machine.states[machine.initial_state_name] end |
Instance Method Details
#current_state_name(name = :default) ⇒ Object
72 73 74 |
# File 'lib/edge-state-machine.rb', line 72 def current_state_name(name = :default) current_state(name).name end |
#fire_event(name = :default, options = {}, event_name) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/edge-state-machine.rb', line 76 def fire_event(name = :default, = {}, event_name) machine = self.class.state_machines[name] event = machine.events[event_name] raise Stateflow::NoEventFound.new("No event matches #{event_name}") if event.nil? event.fire(self, ) end |
#initial_state_name(name = :default) ⇒ Object
58 59 60 61 |
# File 'lib/edge-state-machine.rb', line 58 def initial_state_name(name = :default) machine = self.class.state_machines[name] return machine.initial_state_name end |
#set_current_state(new_state, machine_name = :default, options = {}) ⇒ Object
83 84 85 86 |
# File 'lib/edge-state-machine.rb', line 83 def set_current_state(new_state, machine_name = :default, = {}) save_to_persistence(new_state.name.to_s, machine_name, ) if self.respond_to? :save_to_persistence @current_states[machine_name] = new_state end |