Skip to content

Commit 1561232

Browse files
agirlinggeekq
authored andcommitted
1 parent ed6ea3b commit 1561232

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

lib/workflow.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def assign_workflow(specification_object)
6161
state.events.flat.each do |event|
6262
event_name = event.name
6363
module_eval do
64-
define_method "#{event_name}!".to_sym do |*args|
65-
process_event!(event_name, *args)
64+
define_method "#{event_name}!".to_sym do |*args, **kwargs|
65+
process_event!(event_name, *args, **kwargs)
6666
end
6767

6868
define_method "can_#{event_name}?" do
@@ -94,7 +94,7 @@ def halted_because
9494
@halted_because
9595
end
9696

97-
def process_event!(name, *args)
97+
def process_event!(name, *args, **kwargs)
9898
event = current_state.events.first_applicable(name, self)
9999
raise NoTransitionAllowed.new(
100100
"There is no event #{name.to_sym} defined for the #{current_state} state") \
@@ -107,26 +107,26 @@ def process_event!(name, *args)
107107
from = current_state
108108
to = spec.states[event.transitions_to]
109109

110-
run_before_transition(from, to, name, *args)
110+
run_before_transition(from, to, name, *args, **kwargs)
111111
return false if @halted
112112

113113
begin
114-
return_value = run_action(event.action, *args) || run_action_callback(event.name, *args)
114+
return_value = run_action(event.action, *args, **kwargs) || run_action_callback(event.name, *args, **kwargs)
115115
rescue StandardError => e
116-
run_on_error(e, from, to, name, *args)
116+
run_on_error(e, from, to, name, *args, **kwargs)
117117
end
118118

119119
return false if @halted
120120

121-
run_on_transition(from, to, name, *args)
121+
run_on_transition(from, to, name, *args, **kwargs)
122122

123-
run_on_exit(from, to, name, *args)
123+
run_on_exit(from, to, name, *args, **kwargs)
124124

125125
transition_value = persist_workflow_state to.to_s
126126

127-
run_on_entry(to, from, name, *args)
127+
run_on_entry(to, from, name, *args, **kwargs)
128128

129-
run_after_transition(from, to, name, *args)
129+
run_after_transition(from, to, name, *args, **kwargs)
130130

131131
return_value.nil? ? transition_value : return_value
132132
end
@@ -169,31 +169,31 @@ def check_transition(event)
169169
end
170170
end
171171

172-
def run_before_transition(from, to, event, *args)
173-
instance_exec(from.name, to.name, event, *args, &spec.before_transition_proc) if
172+
def run_before_transition(from, to, event, *args, **kwargs)
173+
instance_exec(from.name, to.name, event, *args, **kwargs, &spec.before_transition_proc) if
174174
spec.before_transition_proc
175175
end
176176

177-
def run_on_error(error, from, to, event, *args)
177+
def run_on_error(error, from, to, event, *args, **kwargs)
178178
if spec.on_error_proc
179-
instance_exec(error, from.name, to.name, event, *args, &spec.on_error_proc)
179+
instance_exec(error, from.name, to.name, event, *args, **kwargs, &spec.on_error_proc)
180180
halt(error.message)
181181
else
182182
raise error
183183
end
184184
end
185185

186-
def run_on_transition(from, to, event, *args)
187-
instance_exec(from.name, to.name, event, *args, &spec.on_transition_proc) if spec.on_transition_proc
186+
def run_on_transition(from, to, event, *args, **kwargs)
187+
instance_exec(from.name, to.name, event, *args, **kwargs, &spec.on_transition_proc) if spec.on_transition_proc
188188
end
189189

190-
def run_after_transition(from, to, event, *args)
191-
instance_exec(from.name, to.name, event, *args, &spec.after_transition_proc) if
190+
def run_after_transition(from, to, event, *args, **kwargs)
191+
instance_exec(from.name, to.name, event, *args, **kwargs, &spec.after_transition_proc) if
192192
spec.after_transition_proc
193193
end
194194

195-
def run_action(action, *args)
196-
instance_exec(*args, &action) if action
195+
def run_action(action, *args, **kwargs)
196+
instance_exec(*args, **kwargs, &action) if action
197197
end
198198

199199
def has_callback?(action)
@@ -206,27 +206,27 @@ def has_callback?(action)
206206
self.private_methods(false).map(&:to_sym).include?(action)
207207
end
208208

209-
def run_action_callback(action_name, *args)
209+
def run_action_callback(action_name, *args, **kwargs)
210210
action = action_name.to_sym
211-
self.send(action, *args) if has_callback?(action)
211+
self.send(action, *args, **kwargs) if has_callback?(action)
212212
end
213213

214-
def run_on_entry(state, prior_state, triggering_event, *args)
214+
def run_on_entry(state, prior_state, triggering_event, *args, **kwargs)
215215
if state.on_entry
216-
instance_exec(prior_state.name, triggering_event, *args, &state.on_entry)
216+
instance_exec(prior_state.name, triggering_event, *args, **kwargs, &state.on_entry)
217217
else
218218
hook_name = "on_#{state}_entry"
219-
self.send hook_name, prior_state, triggering_event, *args if has_callback?(hook_name)
219+
self.send hook_name, prior_state, triggering_event, *args, **kwargs if has_callback?(hook_name)
220220
end
221221
end
222222

223-
def run_on_exit(state, new_state, triggering_event, *args)
223+
def run_on_exit(state, new_state, triggering_event, *args, **kwargs)
224224
if state
225225
if state.on_exit
226-
instance_exec(new_state.name, triggering_event, *args, &state.on_exit)
226+
instance_exec(new_state.name, triggering_event, *args, **kwargs, &state.on_exit)
227227
else
228228
hook_name = "on_#{state}_exit"
229-
self.send hook_name, new_state, triggering_event, *args if has_callback?(hook_name)
229+
self.send hook_name, new_state, triggering_event, *args, **kwargs if has_callback?(hook_name)
230230
end
231231
end
232232
end

0 commit comments

Comments
 (0)