diff --git a/lib/guard.rb b/lib/guard.rb index b5f1865..426c761 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -6,6 +6,7 @@ module Guard autoload :Listener, 'guard/listener' autoload :Watcher, 'guard/watcher' autoload :Notifier, 'guard/notifier' + autoload :Hook, 'guard/hook' class << self attr_accessor :options, :guards, :listener @@ -57,7 +58,9 @@ module Guard # Let a guard execute its task but # fire it if his work leads to a system failure def supervised_task(guard, task_to_supervise, *args) + guard.hook "#{task_to_supervise.to_s}_begin" guard.send(task_to_supervise, *args) + guard.hook "#{task_to_supervise.to_s}_end" rescue Exception UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}") ::Guard.guards.delete guard diff --git a/lib/guard/hook.rb b/lib/guard/hook.rb index 0fadc12..6c62e5f 100644 --- a/lib/guard/hook.rb +++ b/lib/guard/hook.rb @@ -36,7 +36,7 @@ module Guard end def has_callback?(listener, guard_class, event) - listeners(guard_class, event).include? listener + callbacks[[guard_class, event]].include? listener end def notify(guard_class, event) @@ -48,14 +48,6 @@ module Guard def reset! @callbacks = nil end - - private - - def listeners(guard_class, event) - callbacks[[guard_class, event]].inject([]) do |all, arr| - all << arr - end - end end end end