class GitHooks::Installer

Constants

HOOK_SAMPLE_FILE

Attributes

hook[RW]

Public Class Methods

new(hook) click to toggle source
# File lib/git_hooks/installer.rb, line 7
def initialize(hook)
  @hook = hook
end

Public Instance Methods

install(force = false) click to toggle source
# File lib/git_hooks/installer.rb, line 11
def install(force = false)
  return true if installed?

  FileUtils.symlink(
    hook_template_path, File.join('.git', 'hooks', hook), force: force
  )
rescue Errno::EEXIST
  raise GitHooks::Exceptions::UnknowHookPresent, hook
end
installed?() click to toggle source
# File lib/git_hooks/installer.rb, line 21
def installed?
  hook_file = File.join(Dir.pwd, '.git', 'hooks', hook)

  File.symlink?(hook_file) && File.realpath(hook_file) == hook_template_path
end

Private Instance Methods

hook_template_path() click to toggle source
# File lib/git_hooks/installer.rb, line 29
def hook_template_path
  File.join(GitHooks.base_path, HOOK_SAMPLE_FILE)
end