class SuperHooks::Hook
Interface with the list of hooks available
Constants
- LIST
An array of existing git hooks
Attributes
path[R]
The path to the executable
Public Class Methods
new(path)
click to toggle source
The initializer
*path: the path to the executable
# File lib/super_hooks/hook.rb, line 72 def initialize(path) @path = path end
where(name: nil, kind: LIST, level: [:user, :project, :global])
click to toggle source
Find a list of hooks by applying the levels to them
*name: the name of the path (can be partial) *kind: the type of hook. eg: pre-commit *level: the folder to search for hooks: [:user, :project, :global]
Example
# where(name: "rake", kind: ["pre-rebase", "pre-commit"], level: [:user]) # # => [#<SuperHooks::Hook:0x007ffa32030758 @path="/home/franky/.git/git_hooks/pre-rebase/rake"]
Returns an array of Hooks
# File lib/super_hooks/hook.rb, line 23 def where(name: nil, kind: LIST, level: [:user, :project, :global]) hooks = [*level].map { |l| send("#{l}_hooks") } hooks.flatten! hooks.select! { |f| a_hook? f } hooks.select! { |hook| hook =~ /#{name}/ } unless name.nil? hooks.select! { |hook| [*kind].any? { |foo| hook =~ /#{foo}/ } } hooks.map { |hook| new(hook) } end
Also aliased as: all
Private Class Methods
a_hook?(path)
click to toggle source
# File lib/super_hooks/hook.rb, line 60 def a_hook?(path) (File.file? path) && (File.stat(path).executable?) end
global_hooks()
click to toggle source
# File lib/super_hooks/hook.rb, line 50 def global_hooks dirs = Git.command('config hooks.global').split(',') dirs.map do |dir| path = File.join(dir, '**', '*') Dir[path] end rescue SuperHooks::Git::GitError [] end
project_hooks()
click to toggle source
# File lib/super_hooks/hook.rb, line 45 def project_hooks path = File.join(Git.repository, '.git', 'git_hooks', '**', '*') Dir[path] end
user_hooks()
click to toggle source
# File lib/super_hooks/hook.rb, line 40 def user_hooks path = File.join(ENV['HOME'], '.git_hooks', '**', '*') Dir[path] end
Public Instance Methods
description()
click to toggle source
Get a short description of the hook
It gets the description of the file by running the file name with the –about flag
Example
# description # => "A signoff commit msg", Returns a string
# File lib/super_hooks/hook.rb, line 101 def description `#{path} --about`.chomp end
execute!(arguments = '')
click to toggle source
Acatully execute the hook
*arguments: the arguments passed from git
Example
execute("GIT_HEAD_MSG") # => true Returns a boolean indicating if this was a successfull run
# File lib/super_hooks/hook.rb, line 86 def execute!(arguments = '') system("#{path} #{arguments}", out: $stdout, err: $stderr) end
Also aliased as: run