class Kamaze::Project::Tools::Git::Hooks

Provide hooks

Kind of factory registering and building hooks

Attributes

registered_hooks[R]
repository[R]

@return [Kamaze::Project::Tools::Git]

Public Class Methods

new(repository) click to toggle source

@param [Kamaze::Project::Tools::Git] repository

# File lib/kamaze/project/tools/git/hooks.rb, line 46
def initialize(repository)
  @hooks = {}
  @repository = repository

  [:pre_commit].each { |n| self.class.register(n) }

  self.class.registered_hooks.each do |name, klass|
    @hooks[name] = klass.new(repository)
  end
end
register(name, klass = nil) click to toggle source
# File lib/kamaze/project/tools/git/hooks.rb, line 28
def register(name, klass = nil)
  klass ||= proc do
    cname = helper.get(:inflector).classify(name.to_s)

    require_relative "hooks/#{name}"

    helper.get(:inflector).constantize("#{self.name}::#{cname}")
  end.call

  @registered_hooks ||= {}
  @registered_hooks[name] = klass
  self
end

Public Instance Methods

[](key) click to toggle source

@param [Symbol] key @return [nil|Array<Hook>]

# File lib/kamaze/project/tools/git/hooks.rb, line 64
def [](key)
  to_h[key]
end
to_h() click to toggle source

@return [Hash]

# File lib/kamaze/project/tools/git/hooks.rb, line 58
def to_h
  @hooks.freeze
end