Hooks - Add :begin and :end hook to all guard actions via Guard.supervised_task
This commit is contained in:
parent
7916139726
commit
386b0be53d
@ -6,6 +6,7 @@ module Guard
|
|||||||
autoload :Listener, 'guard/listener'
|
autoload :Listener, 'guard/listener'
|
||||||
autoload :Watcher, 'guard/watcher'
|
autoload :Watcher, 'guard/watcher'
|
||||||
autoload :Notifier, 'guard/notifier'
|
autoload :Notifier, 'guard/notifier'
|
||||||
|
autoload :Hook, 'guard/hook'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :options, :guards, :listener
|
attr_accessor :options, :guards, :listener
|
||||||
@ -57,7 +58,9 @@ module Guard
|
|||||||
# Let a guard execute its task but
|
# Let a guard execute its task but
|
||||||
# fire it if his work leads to a system failure
|
# fire it if his work leads to a system failure
|
||||||
def supervised_task(guard, task_to_supervise, *args)
|
def supervised_task(guard, task_to_supervise, *args)
|
||||||
|
guard.hook "#{task_to_supervise.to_s}_begin"
|
||||||
guard.send(task_to_supervise, *args)
|
guard.send(task_to_supervise, *args)
|
||||||
|
guard.hook "#{task_to_supervise.to_s}_end"
|
||||||
rescue Exception
|
rescue Exception
|
||||||
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
|
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
|
||||||
::Guard.guards.delete guard
|
::Guard.guards.delete guard
|
||||||
|
@ -36,7 +36,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def has_callback?(listener, guard_class, event)
|
def has_callback?(listener, guard_class, event)
|
||||||
listeners(guard_class, event).include? listener
|
callbacks[[guard_class, event]].include? listener
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify(guard_class, event)
|
def notify(guard_class, event)
|
||||||
@ -48,14 +48,6 @@ module Guard
|
|||||||
def reset!
|
def reset!
|
||||||
@callbacks = nil
|
@callbacks = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def listeners(guard_class, event)
|
|
||||||
callbacks[[guard_class, event]].inject([]) do |all, arr|
|
|
||||||
all << arr
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user