Class: GitLogTime::Installer
- Inherits:
-
Object
- Object
- GitLogTime::Installer
- Defined in:
- lib/git-log-time/installer.rb
Constant Summary collapse
- TARGET_GIT_PATH =
'.git'
- TARGET_HOOKS_PATH =
'hooks/'
- 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
- #uninstall ⇒ Object
Constructor Details
#initialize(key = nil) ⇒ Installer
Returns a new instance of Installer.
13 14 15 |
# File 'lib/git-log-time/installer.rb', line 13 def initialize(key = nil) @key = key || "default" end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/git-log-time/installer.rb', line 11 def key @key end |
Instance Method Details
#hook ⇒ Object
17 18 19 |
# File 'lib/git-log-time/installer.rb', line 17 def hook templates[key.sub(/^--/, "")] end |
#install ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/git-log-time/installer.rb', line 30 def install if hook then FileUtils.cp(target, target+ ".backup") if File.exist?(target) 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
21 22 23 24 25 26 27 28 |
# File 'lib/git-log-time/installer.rb', line 21 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 + key)) end |
#uninstall ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/git-log-time/installer.rb', line 46 def uninstall back_up_path = target+ ".backup" if File.exist?(back_up_path) FileUtils.mv(back_up_path, target) puts "Moved #{back_up_path} to #{target}" else puts "Git-log-time not Installed" end true end |