Class: Amp::Hook
Overview
Hook
The hook class allows the end-user to easily provide hooks into the code that makes Amp go. For example, one might want to easily hook into the commit command, and send an e-mail out to your team after every commit. You could use the Hook class, as well as the Kernel-level “hook” method, to do this.
Hooks are global, currently - they cannot only be applied to one repo at a time.
Constant Summary collapse
- DEFAULTS =
{:throw => false}
- @@all_hooks =
Hash.new {|h, k| h[k] = []}
Instance Attribute Summary collapse
-
#block ⇒ Object
The block to be executed when the hook is called.
-
#name ⇒ Object
The call symbol this hook is associated with.
Class Method Summary collapse
- .all_hooks ⇒ Object
-
.run_hook(call, opts = {}) ⇒ Object
Call the hooks that run under
call
.
Instance Method Summary collapse
-
#call(opts) ⇒ Object
(also: #run, #[])
Runs the hook.
-
#initialize(name) {|opts| ... } ⇒ Hook
constructor
Registers a hook with the system.
Constructor Details
#initialize(name) {|opts| ... } ⇒ Hook
Registers a hook with the system. A hook is simply a proc that takes some options. The hook has a name, which specifies which action it is hooking into. Some hooks include:
:outgoing
:prechangegroup
:changegroup
52 53 54 55 56 |
# File 'lib/amp/commands/hooks.rb', line 52 def initialize(name, &block) @name = name @block = block @@all_hooks[name] << self end |
Instance Attribute Details
#block ⇒ Object
The block to be executed when the hook is called
38 39 40 |
# File 'lib/amp/commands/hooks.rb', line 38 def block @block end |
#name ⇒ Object
The call symbol this hook is associated with
34 35 36 |
# File 'lib/amp/commands/hooks.rb', line 34 def name @name end |
Class Method Details
.all_hooks ⇒ Object
13 |
# File 'lib/amp/commands/hooks.rb', line 13 def self.all_hooks; @@all_hooks; end |
Instance Method Details
#call(opts) ⇒ Object Also known as: run, []
Runs the hook.
62 63 64 |
# File 'lib/amp/commands/hooks.rb', line 62 def call(opts) @block.call(opts) end |