Module: Workflow::InstanceMethods
- 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
87 88 89 90 91 |
# File 'lib/workflow.rb', line 87 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
142 143 144 145 |
# File 'lib/workflow.rb', line 142 def halt(reason = nil) @halted_because = reason @halted = true end |
#halt!(reason = nil) ⇒ Object
147 148 149 150 151 |
# File 'lib/workflow.rb', line 147 def halt!(reason = nil) @halted_because = reason @halted = true raise TransitionHalted.new(reason) end |
#halted? ⇒ Boolean
See the ‘Guards’ section in the README
95 96 97 |
# File 'lib/workflow.rb', line 95 def halted? @halted end |
#halted_because ⇒ Object
call of halt or halt! method.
101 102 103 |
# File 'lib/workflow.rb', line 101 def halted_because @halted_because end |
#process_event!(name, *args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/workflow.rb', line 105 def process_event!(name, *args) event = current_state.events.first_applicable(name, self) 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 StandardError => 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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/workflow.rb', line 153 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 |