Module: TaliaCore::Workflow::InstanceMethods
- Defined in:
- lib/talia_core/workflow.rb
Instance Method Summary collapse
-
#current_state ⇒ Object
Returns the current state the object is in, as a Ruby symbol.
-
#next_state_for_event(event) ⇒ Object
Returns what the next state for a given event would be, as a Ruby symbol.
- #next_states_for_event(event) ⇒ Object
- #run_initial_state_actions ⇒ Object
-
#set_initial_state ⇒ Object
:nodoc:.
-
#set_initial_state_properties ⇒ Object
:nodoc:.
- #state_properties ⇒ Object
- #state_properties=(value) ⇒ Object
Instance Method Details
#current_state ⇒ Object
Returns the current state the object is in, as a Ruby symbol.
178 179 180 |
# File 'lib/talia_core/workflow.rb', line 178 def current_state self.send(self.class.state_column).to_sym end |
#next_state_for_event(event) ⇒ Object
Returns what the next state for a given event would be, as a Ruby symbol.
183 184 185 186 |
# File 'lib/talia_core/workflow.rb', line 183 def next_state_for_event(event) ns = next_states_for_event(event) ns.empty? ? nil : ns.first.to end |
#next_states_for_event(event) ⇒ Object
188 189 190 191 192 |
# File 'lib/talia_core/workflow.rb', line 188 def next_states_for_event(event) self.class.read_inheritable_attribute(:transition_table)[event.to_sym].select do |s| s.from == current_state end end |
#run_initial_state_actions ⇒ Object
171 172 173 174 175 |
# File 'lib/talia_core/workflow.rb', line 171 def run_initial_state_actions initial = self.class.read_inheritable_attribute(:states)[self.class.initial_state.to_sym] initial.entering(self) initial.entered(self) end |
#set_initial_state ⇒ Object
:nodoc:
163 164 165 |
# File 'lib/talia_core/workflow.rb', line 163 def set_initial_state #:nodoc: write_attribute self.class.state_column, self.class.initial_state.to_s end |
#set_initial_state_properties ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/talia_core/workflow.rb', line 167 def set_initial_state_properties #:nodoc: write_attribute self.class.state_properties_column, Marshal.dump(self.class.initial_state_properties) end |
#state_properties ⇒ Object
155 156 157 |
# File 'lib/talia_core/workflow.rb', line 155 def state_properties Marshal.load(self.send(self.class.state_properties_column)) end |
#state_properties=(value) ⇒ Object
159 160 161 |
# File 'lib/talia_core/workflow.rb', line 159 def state_properties=(value) write_attribute self.class.state_properties_column, Marshal.dump(value) end |