Class: Mercurial::HookFactory

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#repositoryObject (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

#allObject

Finds all repository hooks. Returns an array of Hook instances.

Example:

repository.hooks.all


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