class GitLogTime::Installer

Constants

TARGET_GIT_PATH
TARGET_HOOKS_PATH
TEMPLATE_DIR

Attributes

key[R]

Public Class Methods

new(key = nil) click to toggle source
# File lib/git-log-time/installer.rb, line 13
def initialize(key = nil)
  @key = key || "default"
end

Public Instance Methods

hook() click to toggle source
# File lib/git-log-time/installer.rb, line 17
def hook
  templates[key.sub(/^--/, "")]
end
install() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

templates() click to toggle source
# File lib/git-log-time/installer.rb, line 59
def templates
  return @templates if @templates
  pattern = File.join(TEMPLATE_DIR, "*")

  @templates =
  Dir.glob(pattern).inject({}) do |hash, file|
    key = file.match(/\/([^\/]+?)$/)[1]
    hash[key] = file
    hash
  end
end