Return last hook return value in Dispatcher#emit

This commit is contained in:
Thibault Jouan 2015-04-20 04:41:30 +00:00
parent 7c440e28d2
commit c69a600ca4
2 changed files with 8 additions and 1 deletions

View File

@ -16,7 +16,9 @@ module Uh
end
def emit *key, args: []
@hooks[translate_key key].each { |e| e.call *args }
value = nil
@hooks[translate_key key].each { |e| value = e.call *args }
value
end

View File

@ -45,6 +45,11 @@ module Uh
expect { dispatcher.emit :hook_key }.to throw_symbol :hook_code
end
it 'returns the value returned by a registered hook' do
dispatcher.on(:hook_key) { :hook_code }
expect(dispatcher.emit :hook_key).to eq :hook_code
end
context 'when no hooks are registered for given key' do
it 'does not call another hook' do
dispatcher.on(:hook_key) { throw :hook_code }