class Pushapp::Hook
Constants
- ANSI_COLORS
- HOOK_COLORS
Attributes
remote[RW]
Public Class Methods
new(remote)
click to toggle source
# File lib/pushapp/hook.rb, line 31 def initialize(remote) @remote = remote @config = remote.config @options = remote.options @remote_index = @config.remotes.index(@remote) @remote_color = ANSI_COLORS[HOOK_COLORS[@remote_index % HOOK_COLORS.length].to_sym] @echo_color = ANSI_COLORS[:bright_green] @error_color = ANSI_COLORS[:bright_red] end
Public Instance Methods
setup()
click to toggle source
# File lib/pushapp/hook.rb, line 42 def setup prepare_hook deploy_hook end
Private Instance Methods
colorize()
click to toggle source
# File lib/pushapp/hook.rb, line 69 def colorize %{2>&1 | ruby -e '$stdout.sync = $stderr.sync = true' -pe '$_="#{pre}#\{$_\}"'} end
copy_hook()
click to toggle source
# File lib/pushapp/hook.rb, line 116 def copy_hook # debug "Making hook executable" # TODO: handle missing user? if @remote.host Pushapp::Pipe.run "scp #{Pushapp::TMP_HOOK} #{@remote.user}@#{@remote.host}:#{@remote.path}/.git/hooks/post-receive" else Pushapp::Pipe.run "cp #{Pushapp::TMP_HOOK} #{@remote.path}/.git/hooks/post-receive" end end
deploy_hook()
click to toggle source
# File lib/pushapp/hook.rb, line 91 def deploy_hook # debug "Copying hook for #{@remote.name} to #{@remote.location}" copy_hook set_hook_permissions set_setup_flag end
find_template(template_name)
click to toggle source
# File lib/pushapp/hook.rb, line 81 def find_template(template_name) "#{Pushapp::TEMPLATE_ROOT}/#{template_name}.erb" end
generate_hook()
click to toggle source
# File lib/pushapp/hook.rb, line 98 def generate_hook load_template 'hook/base' end
info(message)
click to toggle source
# File lib/pushapp/hook.rb, line 73 def info message %{ruby -e 'puts "#{pre}\e[#{@echo_color}m\e[1m[pushapp]\e[0m\e[#{@echo_color}m INFO: #{message}\e[0m"'} end
load_template(template_name)
click to toggle source
# File lib/pushapp/hook.rb, line 77 def load_template(template_name) ::ERB.new(File.read(find_template(template_name))).result(binding) end
make_hook_executable()
click to toggle source
# File lib/pushapp/hook.rb, line 126 def make_hook_executable # debug "Making hook executable" "chmod +x #{@remote.path}/.git/hooks/post-receive" end
padded_max_length()
click to toggle source
# File lib/pushapp/hook.rb, line 49 def padded_max_length if @remote.group @config.remotes_grouped_by(@remote.group).map {|r| r.full_name}.max.length else @remote.name.length end end
padded_name()
click to toggle source
# File lib/pushapp/hook.rb, line 57 def padded_name @padden_name ||= @remote.full_name.ljust([padded_max_length, "remote:".length].max) end
pre()
click to toggle source
# File lib/pushapp/hook.rb, line 65 def pre "#\{ENV[\"PAP_PRE\"]\}" end
prefix()
click to toggle source
# File lib/pushapp/hook.rb, line 61 def prefix "\e[1G\e[#{@remote_color}m#{padded_name} |\e[0m " end
prepare_hook()
click to toggle source
# File lib/pushapp/hook.rb, line 85 def prepare_hook # info "Generating and uploading post-receive hook for #{@remote.name}" hook = generate_hook write hook end
set_hook_permissions()
click to toggle source
# File lib/pushapp/hook.rb, line 108 def set_hook_permissions @remote.run "#{make_hook_executable}" end
set_setup_flag()
click to toggle source
# File lib/pushapp/hook.rb, line 112 def set_setup_flag @remote.run "touch #{@remote.path}/.git/.pushapp.setup.flag" end
write(hook)
click to toggle source
# File lib/pushapp/hook.rb, line 102 def write(hook) File.open(Pushapp::TMP_HOOK, "wb") do |f| f.puts hook end end