Sha256: b9b03cd809fe99b406015821c1ad3ea612b2dc4ff18429a23d2d38a9036764ed
Contents?: true
Size: 977 Bytes
Versions: 8
Compression:
Stored size: 977 Bytes
Contents
require 'fileutils' require 'pre-commit/configuration' module PreCommit class Installer TARGET_HOOK_PATH = '.git/hooks/pre-commit' TEMPLATE_DIR = File.expand_path("../../../templates/hooks/", __FILE__) attr_reader :key def initialize(key = nil) @key = key || "default" end def hook templates[key.sub(/^--/, "")] end def target TARGET_HOOK_PATH end 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 private 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 end end
Version data entries
8 entries across 8 versions & 1 rubygems