Class: Mercurial::HookFactory
- Inherits:
-
Object
- Object
- Mercurial::HookFactory
- Defined in:
- lib/mercurial-ruby/factories/hook_factory.rb
Overview
This class is a handy way to manage hooks in your repository.
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Instance of Repository.
Instance Method Summary collapse
-
#add(name, value) ⇒ Object
Adds a new hook to the repository.
-
#all ⇒ Object
Finds all repository hooks.
-
#by_name(name) ⇒ Object
Finds a specific hook by it’s name.
-
#initialize(repository) ⇒ HookFactory
constructor
A new instance of HookFactory.
-
#remove(name) ⇒ Object
Removes a hook from the repository.
Constructor Details
#initialize(repository) ⇒ HookFactory
Returns a new instance of HookFactory.
11 12 13 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 11 def initialize(repository) @repository = repository end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Instance of Repository.
9 10 11 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 9 def repository @repository end |
Instance Method Details
#add(name, value) ⇒ Object
Adds a new hook to the repository.
Example:
repository.hooks.add('changegroup', 'do_something')
47 48 49 50 51 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 47 def add(name, value) build(name, value).tap do |hook| hook.save end end |
#all ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 21 def all [].tap do |returning| repository.config.find_header('hooks').each_pair do |name, value| returning << build(name, value) end end end |
#by_name(name) ⇒ Object
Finds a specific hook by it’s name. Returns an instance of Hook.
Example:
repository.hooks.by_name('changegroup')
35 36 37 38 39 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 35 def by_name(name) all.find do |h| h.name == name.to_s end end |
#remove(name) ⇒ Object
Removes a hook from the repository.
Example:
repository.hooks.remove('changegroup')
59 60 61 62 63 |
# File 'lib/mercurial-ruby/factories/hook_factory.rb', line 59 def remove(name) if hook = by_name(name) hook.destroy! end end |