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
haltorhalt!method. - #process_event!(name, *args) ⇒ Object
- #spec ⇒ Object
Instance Method Details
#current_state ⇒ Object
168 169 170 171 172 |
# File 'lib/workflow.rb', line 168 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
223 224 225 226 |
# File 'lib/workflow.rb', line 223 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
228 229 230 231 232 |
# File 'lib/workflow.rb', line 228 def halt!(reason = nil) @halted_because = reason @halted = true raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
176 177 178 |
# File 'lib/workflow.rb', line 176 def halted? @halted end |
#halted_because ⇒ Object
call of halt or halt! method.
182 183 184 |
# File 'lib/workflow.rb', line 182 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/workflow.rb', line 186 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 check_transition(event) from = current_state to = spec.states[event.transitions_to] run_before_transition(from, to, name, *args) return false if @halted begin return_value = run_action(event.action, *args) || run_action_callback(event.name, *args) rescue Exception => e run_on_error(e, from, to, name, *args) end return false if @halted run_on_transition(from, to, name, *args) run_on_exit(from, to, name, *args) transition_value = persist_workflow_state to.to_s run_on_entry(to, from, name, *args) run_after_transition(from, to, name, *args) return_value.nil? ? transition_value : return_value end |
#spec ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/workflow.rb', line 234 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 |