Skip to content

Commit 53e7ae1

Browse files
committed
Merge remote-tracking branch 'dwbutler/master'. Include issue number
2 parents 8496110 + 7214ade commit 53e7ae1

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/workflow.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,14 @@ def run_after_transition(from, to, event, *args)
266266
def run_action(action, *args)
267267
instance_exec(*args, &action) if action
268268
end
269+
270+
def has_callback?(action)
271+
self.respond_to?(action) or self.class.private_method_defined?(action)
272+
end
269273

270274
def run_action_callback(action_name, *args)
271-
self.send action_name.to_sym, *args if self.respond_to?(action_name.to_sym)
275+
action = action_name.to_sym
276+
self.send(action, *args) if has_callback?(action)
272277
end
273278

274279
def run_on_entry(state, prior_state, triggering_event, *args)

test/main_test.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,36 @@ def my_transition(args)
279279
end
280280
state :two
281281
end
282+
283+
private
284+
def another_transition(args)
285+
args.another_tran
286+
end
287+
end
288+
a = c.new
289+
a.my_transition!(args)
290+
end
291+
292+
test '#53 Support for private transition callbacks' do
293+
args = mock()
294+
args.expects(:log).once
295+
c = Class.new
296+
c.class_eval do
297+
include Workflow
298+
workflow do
299+
state :new do
300+
event :assign, :transitions_to => :assigned
301+
end
302+
state :assigned
303+
end
304+
305+
private
306+
def assign(args)
307+
args.log('Assigned')
308+
end
282309
end
283-
c.new.my_transition!(args)
310+
a = c.new
311+
a.assign!(args)
284312
end
285313

286314
test 'Single table inheritance (STI)' do

0 commit comments

Comments
 (0)