Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow protected/private on_entry/on_exit callbacks #81

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def run_on_entry(state, prior_state, triggering_event, *args)
instance_exec(prior_state.name, triggering_event, *args, &state.on_entry)
else
hook_name = "on_#{state}_entry"
self.send hook_name, prior_state, triggering_event, *args if self.respond_to? hook_name
self.send hook_name, prior_state, triggering_event, *args if has_callback? hook_name
end
end

Expand All @@ -197,7 +197,7 @@ def run_on_exit(state, new_state, triggering_event, *args)
instance_exec(new_state.name, triggering_event, *args, &state.on_exit)
else
hook_name = "on_#{state}_exit"
self.send hook_name, new_state, triggering_event, *args if self.respond_to? hook_name
self.send hook_name, new_state, triggering_event, *args if has_callback? hook_name
end
end
end
Expand Down
17 changes: 12 additions & 5 deletions test/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ def my_transition(args)
end
state :two
end

private
def another_transition(args)
args.another_tran
end
end
a = c.new
a.my_transition!(args)
Expand All @@ -281,6 +276,8 @@ def another_transition(args)
test '#53 Support for non public transition callbacks' do
args = mock()
args.expects(:log).with('in private callback').once
args.expects(:log).with('in protected on_exit callback').twice
args.expects(:log).with('in protected on_entry callback').once
args.expects(:log).with('in protected callback in the base class').once

b = Class.new # the base class with a protected callback
Expand All @@ -303,6 +300,16 @@ def assign_old(args)
state :assigned_old
end

protected

def on_new_exit new_state, event, args
args.log('in protected on_exit callback')
end

def on_assigned_entry prior_state, event, args
args.log('in protected on_entry callback')
end

private
def assign(args)
args.log('in private callback')
Expand Down