class GitSleep::HookInstaller
Attributes
event[R]
Public Class Methods
install(event)
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 3 def self.install(event) new(event).install end
new(event)
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 9 def initialize(event) @event = event end
Public Instance Methods
install()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 13 def install (return unless ok_to_overwrite?) if File.exist?(new_hook_path) move_hook_code_into_place make_hook_executable puts 'Hook installed and made executable' end
Private Instance Methods
already_exists_warning_text()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 55 def already_exists_warning_text "you already have a #{event} hook and we don't want to overwrite it..." end
current_path()
click to toggle source
TODO: make sure this will be the path the user is currently in
# File lib/git-sleep/hook_installer.rb, line 51 def current_path File.expand_path('.') end
hook_code()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 38 def hook_code File.read(hook_code_path) end
hook_code_path()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 42 def hook_code_path File.expand_path("../../../hooks/#{event}", __FILE__) end
make_hook_executable()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 34 def make_hook_executable `chmod a+x #{new_hook_path}` end
move_hook_code_into_place()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 28 def move_hook_code_into_place File.open(new_hook_path, 'w') do |f| f.write hook_code end end
new_hook_path()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 46 def new_hook_path current_path + '/.git/hooks/' + event end
ok_to_overwrite?()
click to toggle source
# File lib/git-sleep/hook_installer.rb, line 22 def ok_to_overwrite? puts already_exists_warning_text print 'Is it okay? [y/n] ' $stdin.gets.chomp == 'y' end