Class: Penchant::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/penchant/hooks.rb

Constant Summary collapse

HOOKS_DIR =
'script/hooks'
GIT_HOOKS_DIR =
'.git/hooks'

Class Method Summary collapse

Class Method Details

.git?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/penchant/hooks.rb', line 30

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

.install!Object



20
21
22
23
24
25
26
27
28
# File 'lib/penchant/hooks.rb', line 20

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

.installed?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/penchant/hooks.rb', line 8

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