Class: Historian::Git::Hooker
- Inherits:
-
Object
- Object
- Historian::Git::Hooker
- Defined in:
- lib/historian/git.rb
Instance Attribute Summary collapse
-
#hook ⇒ Object
Returns the value of attribute hook.
-
#repo_dir ⇒ Object
Returns the value of attribute repo_dir.
Instance Method Summary collapse
- #create_hook_script ⇒ Object
- #create_hook_scripts_dir ⇒ Object
- #create_hook_wrapper_script ⇒ Object
- #hook_script ⇒ Object
- #hook_scripts_dir ⇒ Object
- #hook_to_git ⇒ Object
- #hook_wrapper_script ⇒ Object
- #hooks_dir ⇒ Object
-
#initialize(repo_dir, hook) ⇒ Hooker
constructor
A new instance of Hooker.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #other_git_hook_exists? ⇒ Boolean
- #preserve_original ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(repo_dir, hook) ⇒ Hooker
Returns a new instance of Hooker.
9 10 11 12 |
# File 'lib/historian/git.rb', line 9 def initialize(repo_dir, hook) self.repo_dir = repo_dir self.hook = hook end |
Instance Attribute Details
#hook ⇒ Object
Returns the value of attribute hook.
7 8 9 |
# File 'lib/historian/git.rb', line 7 def hook @hook end |
#repo_dir ⇒ Object
Returns the value of attribute repo_dir.
7 8 9 |
# File 'lib/historian/git.rb', line 7 def repo_dir @repo_dir end |
Instance Method Details
#create_hook_script ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/historian/git.rb', line 14 def create_hook_script File.open(hook_script, "w") do |f| f.puts "#!/bin/bash" f.puts "historian #{hook.to_s} $@" end File.chmod 0755, hook_script end |
#create_hook_scripts_dir ⇒ Object
22 23 24 |
# File 'lib/historian/git.rb', line 22 def create_hook_scripts_dir Dir.mkdir hook_scripts_dir unless File.directory? hook_scripts_dir end |
#create_hook_wrapper_script ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/historian/git.rb', line 26 def create_hook_wrapper_script File.open(hook_wrapper_script, "w") do |f| script = <<-EOF #!/bin/bash # # Git hook modified by Historian. Do not modify this file. # Add more hooks in the #{hook_to_git}.d directory. # BASE=`dirname $0` for S in $BASE/#{hook_to_git}.d/* do $S $@ || exit $? done EOF f.puts script.gsub(/^\s+/,'') end File.chmod 0755, hook_wrapper_script end |
#hook_script ⇒ Object
49 50 51 |
# File 'lib/historian/git.rb', line 49 def hook_script File.join hook_scripts_dir, "historian" end |
#hook_scripts_dir ⇒ Object
53 54 55 |
# File 'lib/historian/git.rb', line 53 def hook_scripts_dir File.join hooks_dir, hook_to_git + ".d" end |
#hook_to_git ⇒ Object
57 58 59 |
# File 'lib/historian/git.rb', line 57 def hook_to_git hook.to_s.gsub "_", "-" end |
#hook_wrapper_script ⇒ Object
61 62 63 |
# File 'lib/historian/git.rb', line 61 def hook_wrapper_script File.join hooks_dir, hook_to_git end |
#hooks_dir ⇒ Object
65 66 67 |
# File 'lib/historian/git.rb', line 65 def hooks_dir File.join repo_dir, ".git", "hooks" end |
#install ⇒ Object
69 70 71 72 73 |
# File 'lib/historian/git.rb', line 69 def install create_hook_scripts_dir create_hook_script create_hook_wrapper_script end |
#installed? ⇒ Boolean
75 76 77 |
# File 'lib/historian/git.rb', line 75 def installed? File.exists? hook_script end |
#other_git_hook_exists? ⇒ Boolean
45 46 47 |
# File 'lib/historian/git.rb', line 45 def other_git_hook_exists? File.exists?(hook_wrapper_script) && !File.directory?(hook_scripts_dir) end |
#preserve_original ⇒ Object
79 80 81 82 |
# File 'lib/historian/git.rb', line 79 def preserve_original create_hook_scripts_dir FileUtils.cp hook_wrapper_script, File.join(hook_scripts_dir, "original") end |
#update ⇒ Object
84 85 86 |
# File 'lib/historian/git.rb', line 84 def update create_hook_script end |