class Mercurial::HookFactory

This class is a handy way to manage hooks in your repository.

Attributes

repository[R]

Instance of {Mercurial::Repository Repository}.

Public Class Methods

new(repository) click to toggle source
# File lib/mercurial-ruby/factories/hook_factory.rb, line 11
def initialize(repository)
  @repository = repository
end

Public Instance Methods

add(name, value) click to toggle source

Adds a new hook to the repository.

Example:

repository.hooks.add('changegroup', 'do_something')
# 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() click to toggle source

Finds all repository hooks. Returns an array of {Mercurial::Hook Hook} instances.

Example:

repository.hooks.all
# 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) click to toggle source

Finds a specific hook by it's name. Returns an instance of {Mercurial::Hook Hook}.

Example:

repository.hooks.by_name('changegroup')
# 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) click to toggle source

Removes a hook from the repository.

Example:

repository.hooks.remove('changegroup')
# File lib/mercurial-ruby/factories/hook_factory.rb, line 59
def remove(name)
  if hook = by_name(name)
    hook.destroy!
  end
end

Protected Instance Methods

build(name, value) click to toggle source
# File lib/mercurial-ruby/factories/hook_factory.rb, line 67
def build(name, value)
  Mercurial::Hook.new(repository, name, value)
end