Module: Workflow::WorkflowInstanceMethods
- Defined in:
- lib/workflow.rb
Instance Method Summary collapse
- #current_state ⇒ Object
- #halt(reason = nil) ⇒ Object
- #halt!(reason = nil) ⇒ Object
-
#halted? ⇒ Boolean
See the ‘Guards’ section in the README.
-
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
- #process_event!(name, *args) ⇒ Object
- #spec ⇒ Object
Instance Method Details
#current_state ⇒ Object
137 138 139 140 141 |
# File 'lib/workflow.rb', line 137 def current_state loaded_state = load_workflow_state res = spec.states[loaded_state.to_sym] if loaded_state res || spec.initial_state end |
#halt(reason = nil) ⇒ Object
175 176 177 178 |
# File 'lib/workflow.rb', line 175 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
180 181 182 183 184 |
# File 'lib/workflow.rb', line 180 def halt!(reason = nil) @halted_because = reason @halted = true raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
145 146 147 |
# File 'lib/workflow.rb', line 145 def halted? @halted end |
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
151 152 153 |
# File 'lib/workflow.rb', line 151 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/workflow.rb', line 155 def process_event!(name, *args) event = current_state.events[name.to_sym] raise NoTransitionAllowed.new( "There is no event #{name.to_sym} defined for the #{current_state} state") \ if event.nil? @halted_because = nil @halted = false return_value = run_action(event.action, *args) || run_action_callback(event.name, *args) if @halted return false else check_transition(event) run_on_transition(current_state, spec.states[event.transitions_to], name, *args) transition_value = transition( current_state, spec.states[event.transitions_to], name, *args ) return_value.nil? ? transition_value : return_value end end |
#spec ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/workflow.rb', line 186 def spec # check the singleton class first class << self return workflow_spec if workflow_spec end c = self.class # using a simple loop instead of class_inheritable_accessor to avoid # dependency on Rails' ActiveSupport until c.workflow_spec || !(c.include? Workflow) c = c.superclass end c.workflow_spec end |