Class: GitHooks::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/git_hooks/installer.rb

Constant Summary collapse

HOOK_SAMPLE_FILE =
'hook.sample'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook) ⇒ Installer

Returns a new instance of Installer.



7
8
9
# File 'lib/git_hooks/installer.rb', line 7

def initialize(hook)
  @hook = hook
end

Instance Attribute Details

#hookObject

Returns the value of attribute hook.



3
4
5
# File 'lib/git_hooks/installer.rb', line 3

def hook
  @hook
end

Instance Method Details

#install(force = false) ⇒ Object



11
12
13
14
15
16
17
18
19
# 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?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# 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