Class: PreCommit::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/pre-commit/installer.rb

Constant Summary collapse

TARGET_HOOK_PATH =
'.git/hooks/pre-commit'
TEMPLATE_DIR =
File.expand_path("../../../templates/hooks/", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil) ⇒ Installer

Returns a new instance of Installer.



13
14
15
# File 'lib/pre-commit/installer.rb', line 13

def initialize(key = nil)
  @key = key || "default"
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/pre-commit/installer.rb', line 11

def key
  @key
end

Instance Method Details

#hookObject



17
18
19
# File 'lib/pre-commit/installer.rb', line 17

def hook
  templates[key.sub(/^--/, "")]
end

#installObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pre-commit/installer.rb', line 25

def install
  if
    hook
  then
    FileUtils.cp(hook, target)
    FileUtils.chmod(0755, target)
    puts "Installed #{hook} to #{target}"
    true
  else
    warn "Could not find template #{key}"
    false
  end
end

#targetObject



21
22
23
# File 'lib/pre-commit/installer.rb', line 21

def target
  TARGET_HOOK_PATH
end