Class: PreCommit::Installer
- Inherits:
-
Object
- Object
- PreCommit::Installer
- Defined in:
- lib/pre-commit/installer.rb
Constant Summary collapse
- TARGET_GIT_PATH =
'.git'
- TARGET_HOOKS_PATH =
'hooks/pre-commit'
- TEMPLATE_DIR =
File.("../../../templates/hooks/", __FILE__)
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #hook ⇒ Object
-
#initialize(key = nil) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #target ⇒ Object
Constructor Details
#initialize(key = nil) ⇒ Installer
Returns a new instance of Installer.
14 15 16 |
# File 'lib/pre-commit/installer.rb', line 14 def initialize(key = nil) @key = key || "default" end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/pre-commit/installer.rb', line 12 def key @key end |
Instance Method Details
#hook ⇒ Object
18 19 20 |
# File 'lib/pre-commit/installer.rb', line 18 def hook templates[key.sub(/^--/, "")] end |
#install ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pre-commit/installer.rb', line 31 def install if hook then FileUtils.mkdir_p(File.dirname(target)) FileUtils.cp(hook, target) FileUtils.chmod(0755, target) puts "Installed #{hook} to #{target}" true else warn "Could not find template #{key}" false end end |
#target ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/pre-commit/installer.rb', line 22 def target target_git_path = if File.directory?(TARGET_GIT_PATH) then TARGET_GIT_PATH else File.readlines('.git').first.match(/gitdir: (.*)$/)[1] end File.join(target_git_path, TARGET_HOOKS_PATH) end |