Module: Workflow::WorkflowInstanceMethods
- Defined in:
- lib/workflow.rb
Instance Attribute Summary collapse
-
#in_entry ⇒ Object
Returns the value of attribute in_entry.
-
#in_exit ⇒ Object
Returns the value of attribute in_exit.
-
#in_transition ⇒ Object
Returns the value of attribute in_transition.
Instance Method Summary collapse
- #clear_transition_flags ⇒ Object
- #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
- #set_transition_flags(current_state, target_state, event) ⇒ Object
- #spec ⇒ Object
Instance Attribute Details
#in_entry ⇒ Object
Returns the value of attribute in_entry.
186 187 188 |
# File 'lib/workflow.rb', line 186 def in_entry @in_entry end |
#in_exit ⇒ Object
Returns the value of attribute in_exit.
186 187 188 |
# File 'lib/workflow.rb', line 186 def in_exit @in_exit end |
#in_transition ⇒ Object
Returns the value of attribute in_transition.
186 187 188 |
# File 'lib/workflow.rb', line 186 def in_transition @in_transition end |
Instance Method Details
#clear_transition_flags ⇒ Object
236 237 238 |
# File 'lib/workflow.rb', line 236 def clear_transition_flags set_transition_flags nil, nil, nil end |
#current_state ⇒ Object
188 189 190 191 192 |
# File 'lib/workflow.rb', line 188 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
240 241 242 243 |
# File 'lib/workflow.rb', line 240 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
245 246 247 248 |
# File 'lib/workflow.rb', line 245 def halt!(reason = nil) halt reason raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
196 197 198 |
# File 'lib/workflow.rb', line 196 def halted? @halted end |
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
202 203 204 |
# File 'lib/workflow.rb', line 202 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/workflow.rb', line 206 def process_event!(name, *args) assure_transition_allowed! name event = current_state.events[name.to_sym] assure_target_state_exists!(event) set_transition_flags(current_state, spec.states[event.transitions_to], event) @halted_because = nil @halted = false return_value = run_action(event.action, *args) || run_action_callback(event.name, *args) if @halted run_on_failed_transition(*args) return_value = false else if event.perform_validation? and not valid? halt :validation_failed run_on_failed_transition(*args) @halted = true # make sure this one is not reset in the on_failed_transition callback return_value = false else transition(*args) end end return_value.nil? ? true : return_value end |
#set_transition_flags(current_state, target_state, event) ⇒ Object
230 231 232 233 234 |
# File 'lib/workflow.rb', line 230 def set_transition_flags(current_state, target_state, event) @in_exit = current_state @in_entry = target_state @in_transition = event end |
#spec ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/workflow.rb', line 250 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 |