Commit 099e338f authored by Kyle Fuller's avatar Kyle Fuller

[HooksManager] Change order of arguments for register

“Register slather for post install” vs “Register for post install
slather”
parent b9ca7654
......@@ -61,19 +61,25 @@ module Pod
# Registers a block for the hook with the given name.
#
# @param [Symbol] name
# The name of the notification.
#
# @param [String] plugin_name
# The name of the plugin the hook comes from.
#
# @param [Symbol] hook_name
# The name of the notification.
#
# @param [Proc] block
# The block.
#
def register(name, plugin_name = nil, &block)
def register(plugin_name, hook_name = nil, &block)
# TODO: Backwards compatibility with nameless plugins from CP 0.34
if hook_name.nil?
hook_name = plugin_name
plugin_name = nil
end
@registrations ||= {}
@registrations[name] ||= []
@registrations[name] << Hook.new(name, plugin_name, block)
@registrations[hook_name] ||= []
@registrations[hook_name] << Hook.new(hook_name, plugin_name, block)
end
# Runs all the registered blocks for the hook with the given name.
......
......@@ -9,7 +9,7 @@ module Pod
describe 'register' do
it 'allows to register a block for a notification with a given name' do
@hooks_manager.register(:post_install, 'plugin') {}
@hooks_manager.register('plugin', :post_install) {}
@hooks_manager.registrations[:post_install].count.should == 1
hook = @hooks_manager.registrations[:post_install].first
hook.class.should == HooksManager::Hook
......@@ -59,7 +59,7 @@ module Pod
end
it 'only runs hooks from the allowed plugins' do
@hooks_manager.register(:post_install, 'plugin') do |_options|
@hooks_manager.register('plugin', :post_install) do |_options|
raise 'Should not be called'
end
......@@ -69,7 +69,7 @@ module Pod
end
it 'passed along user-specified options when the hook block has arity 2' do
@hooks_manager.register(:post_install, 'plugin') do |_options, user_options|
@hooks_manager.register('plugin', :post_install) do |_options, user_options|
user_options['key'].should == 'value'
end
......@@ -99,7 +99,7 @@ module Pod
it 'prints a message in verbose mode for each hook run' do
config.verbose = true
@hooks_manager.register(:post_install, 'plugin') {}
@hooks_manager.register('plugin', :post_install) {}
@hooks_manager.run(:post_install, Object.new)
UI.output.should.match %r{- plugin from `spec/unit/hooks_manager_spec.rb`}
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment