Sha256: 0350ba17453b86b81752d30b043e6ec2fe9a7fc4eac583941c69d7fe23c9ce5a

Contents?: true

Size: 809 Bytes

Versions: 4

Compression:

Stored size: 809 Bytes

Contents

require 'pathname'

module Penchant
  class Hooks
    HOOKS_DIR = 'script/hooks'
    GIT_HOOKS_DIR = '.git/hooks'

    def self.installed?
      if File.directory?(HOOKS_DIR)
        Dir[File.join(HOOKS_DIR, '*')].each do |file|
          target = File.join(GIT_HOOKS_DIR, File.basename(file))
          return false if !File.symlink?(target)
          return false if !File.expand_path(File.readlink(target)) == File.expand_path(file)
        end
      end

      true
    end

    def self.install!
      if git?
        puts "[penchant] installing git hooks"

        Dir['script/hooks/*'].each do |hook|
          FileUtils.ln_sf File.join(Dir.pwd, hook), "#{GIT_HOOKS_DIR}/#{File.split(hook).last}"
        end
      end
    end

    def self.git?
      File.directory?(GIT_HOOKS_DIR)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
penchant-0.2.29 lib/penchant/hooks.rb
penchant-0.2.28 lib/penchant/hooks.rb
penchant-0.2.27 lib/penchant/hooks.rb
penchant-0.2.26 lib/penchant/hooks.rb