Module: Workflow::WorkflowInstanceMethods
- Defined in:
- lib/workflow.rb
Instance Method Summary
- - (Object) current_state
- - (Object) halt(reason = nil)
- - (Object) halt!(reason = nil)
-
- (Boolean) halted?
See the ‘Guards’ section in the README.
-
- (Object) halted_because
call of `halt` or `halt!` method.
- - (Object) process_event!(name, *args)
- - (Object) spec
Instance Method Details
- (Object) current_state
146 147 148 149 150 |
# File 'lib/workflow.rb', line 146 def current_state loaded_state = load_workflow_state res = spec.states[loaded_state.to_sym] if loaded_state res || spec.initial_state end |
- (Object) halt(reason = nil)
196 197 198 199 |
# File 'lib/workflow.rb', line 196 def halt(reason = nil) @halted_because = reason @halted = true end |
- (Object) halt!(reason = nil)
201 202 203 204 205 |
# File 'lib/workflow.rb', line 201 def halt!(reason = nil) @halted_because = reason @halted = true raise TransitionHalted.new(reason) end |
- (Boolean) halted?
See the ‘Guards’ section in the README
154 155 156 |
# File 'lib/workflow.rb', line 154 def halted? @halted end |
- (Object) halted_because
call of `halt` or `halt!` method.
160 161 162 |
# File 'lib/workflow.rb', line 160 def halted_because @halted_because end |
- (Object) process_event!(name, *args)
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/workflow.rb', line 164 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(current_state, spec.states[event.transitions_to], name, *args) return false if @halted return_value = run_action(event.action, *args) || run_action_callback(event.name, *args) 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 |
- (Object) spec
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/workflow.rb', line 207 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 |