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.
181 182 183 |
# File 'lib/workflow.rb', line 181 def in_entry @in_entry end |
#in_exit ⇒ Object
Returns the value of attribute in_exit.
181 182 183 |
# File 'lib/workflow.rb', line 181 def in_exit @in_exit end |
#in_transition ⇒ Object
Returns the value of attribute in_transition.
181 182 183 |
# File 'lib/workflow.rb', line 181 def in_transition @in_transition end |
Instance Method Details
#clear_transition_flags ⇒ Object
231 232 233 |
# File 'lib/workflow.rb', line 231 def clear_transition_flags set_transition_flags nil, nil, nil end |
#current_state ⇒ Object
183 184 185 186 187 |
# File 'lib/workflow.rb', line 183 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
235 236 237 238 |
# File 'lib/workflow.rb', line 235 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
240 241 242 243 |
# File 'lib/workflow.rb', line 240 def halt!(reason = nil) halt reason raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
191 192 193 |
# File 'lib/workflow.rb', line 191 def halted? @halted end |
#halted_because ⇒ Object
call of ‘halt` or `halt!` method.
197 198 199 |
# File 'lib/workflow.rb', line 197 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/workflow.rb', line 201 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
225 226 227 228 229 |
# File 'lib/workflow.rb', line 225 def set_transition_flags(current_state, target_state, event) @in_exit = current_state @in_entry = target_state @in_transition = event end |
#spec ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/workflow.rb', line 245 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 |