class SuperHooks::Installer

Class responsible for installing and uninstalling the SuperHooks

Public Instance Methods

remove()
Alias for: uninstall
run() click to toggle source

Run the installer

This will create a copy of the .git/hooks folder to .git/hooks.old And create new files for future hooks to user SuperHooks

Examples

run
# => true
# File lib/super_hooks/installer.rb, line 51
def run
  if already_installed?
    $stderr.puts 'SuperHooks already installed'
    exit 1
  end
  copy_to_backup_folder
  create_new_files
end
uninstall() click to toggle source

Uninstall GitHooks

This will do the following

  • remove the projects .git/git_hooks folder

  • rename the .git/hooks.old/ folder to .git/hooks/

# File lib/super_hooks/installer.rb, line 67
def uninstall
  unless already_installed?
    $stderr.puts 'SuperHooks is not installed'
    exit 1
  end

  remove_hooks_folder
  restore_old_folder
end
Also aliased as: remove

Private Instance Methods

already_installed?() click to toggle source
# File lib/super_hooks/installer.rb, line 80
def already_installed?
  ::File.exist?(hook_folder + '.old')
end
copy_to_backup_folder() click to toggle source
# File lib/super_hooks/installer.rb, line 84
def copy_to_backup_folder
  FileUtils.mv(hook_folder, hook_folder + '.old')
end
create_new_files() click to toggle source
# File lib/super_hooks/installer.rb, line 92
def create_new_files
  Dir.mkdir(hook_folder)

  Hook::LIST.each do |hook|
    file = File.join(Git.repository, '.git', 'hooks', hook)
    FileUtils.cp(ROOT.join('templates', 'hook'), file)
  end
end
hook_folder() click to toggle source
# File lib/super_hooks/installer.rb, line 88
def hook_folder
  File.join(Git.repository, '.git', 'hooks')
end
remove_hooks_folder() click to toggle source
# File lib/super_hooks/installer.rb, line 101
def remove_hooks_folder
  FileUtils.rm_rf(hook_folder)
end
restore_old_folder() click to toggle source
# File lib/super_hooks/installer.rb, line 105
def restore_old_folder
  FileUtils.mv(hook_folder + '.old', hook_folder)
end