From c69a600ca494937c67c06e83dbcc2f356064f5ab Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Mon, 20 Apr 2015 04:41:30 +0000 Subject: [PATCH] Return last hook return value in Dispatcher#emit --- lib/uh/wm/dispatcher.rb | 4 +++- spec/uh/wm/dispatcher_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/uh/wm/dispatcher.rb b/lib/uh/wm/dispatcher.rb index e49eac2..61a589c 100644 --- a/lib/uh/wm/dispatcher.rb +++ b/lib/uh/wm/dispatcher.rb @@ -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 diff --git a/spec/uh/wm/dispatcher_spec.rb b/spec/uh/wm/dispatcher_spec.rb index 15cfc6c..00429bc 100644 --- a/spec/uh/wm/dispatcher_spec.rb +++ b/spec/uh/wm/dispatcher_spec.rb @@ -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 }