class TinyCI::Installer
Responsible for writing the git hook file
Public Class Methods
new(working_dir: nil, logger: nil, absolute_path: false)
click to toggle source
Constructor
@param [String] working_dir The directory from which to run. Does not have to be the root of the repo. @param [Logger] logger Logger object
# File lib/tinyci/installer.rb, line 16 def initialize(working_dir: nil, logger: nil, absolute_path: false) @logger = logger @working_dir = working_dir || repo_root @absolute_path = absolute_path end
Public Instance Methods
install!()
click to toggle source
Write the hook to the relevant path and make it executable
# File lib/tinyci/installer.rb, line 23 def install! unless inside_repository? log_error 'not currently in a git repository' return false end if hook_exists? log_error 'post-update hook already exists in this repository' return false end File.open(hook_path, 'a') { |f| f.write hook_content } FileUtils.chmod('u+x', hook_path) log_info 'tinyci post-update hook installed successfully' end
Private Instance Methods
bin_path()
click to toggle source
# File lib/tinyci/installer.rb, line 50 def bin_path @absolute_path ? Gem.bin_path('tinyci', 'tinyci') : 'tinyci' end
hook_content()
click to toggle source
# File lib/tinyci/installer.rb, line 54 def hook_content <<~HOOK #!/bin/sh unset GIT_DIR #{bin_path} run --all HOOK end
hook_exists?()
click to toggle source
# File lib/tinyci/installer.rb, line 42 def hook_exists? File.exist? hook_path end
hook_path()
click to toggle source
# File lib/tinyci/installer.rb, line 46 def hook_path File.expand_path('hooks/post-update', git_directory_path) end