class Pushapp::Remote

Attributes

config[R]
group[R]
location[R]
name[R]
options[R]
tasks[R]

Public Class Methods

new(name, group, location, config, options = {}) click to toggle source
# File lib/pushapp/remote.rb, line 13
def initialize(name, group, location, config, options = {})
  @name     = name
  @location = location
  @config   = config
  @options  = options
  @group    = group
  @tasks    = Hash.new { |hash, key| hash[key] = [] }
end

Public Instance Methods

env() click to toggle source
# File lib/pushapp/remote.rb, line 105
def env
  (options[:env] || {})
end
env_run(cmd) click to toggle source
# File lib/pushapp/remote.rb, line 85
def env_run cmd
  if host
    Pushapp::Pipe.run "ssh #{user}@#{host} 'cd #{path} && #{shell_env} $SHELL -l -c \"#{cmd}\"'"
  else
    Bundler.with_original_env do
      Pushapp::Pipe.run "cd #{path} && #{shell_env} #{cmd}"
    end
  end
end
exec(cmd) click to toggle source
# File lib/pushapp/remote.rb, line 77
def exec cmd
  if host
    Kernel.exec "ssh -t #{user}@#{host} '#{cmd}'"
  else
    Kernel.exec cmd
  end
end
full_name() click to toggle source
# File lib/pushapp/remote.rb, line 22
def full_name
  [group, name].compact.join('-')
end
host() click to toggle source
# File lib/pushapp/remote.rb, line 55
def host
  host = @location.match(/@(.*):/)
  host[1] unless host.nil?
end
on(event, &block) click to toggle source
# File lib/pushapp/remote.rb, line 38
def on event, &block
  @event = event.to_s
  instance_eval(&block) if block_given?
end
path() click to toggle source
# File lib/pushapp/remote.rb, line 47
def path
  if host
    @location.match(/:(.*)$/)[1]
  else
    @location
  end
end
rake(task_name, task_options={}) click to toggle source
# File lib/pushapp/remote.rb, line 26
def rake(task_name, task_options={})
  tasks[@event] << Pushapp::Tasks::Rake.new(task_name, merge_options(task_options))
end
run(cmd) click to toggle source
# File lib/pushapp/remote.rb, line 95
def run cmd
  if host
    Pushapp::Pipe.run "ssh #{user}@#{host} '#{cmd}'"
  else
    Bundler.with_original_env do
      Pushapp::Pipe.run cmd
    end
  end
end
script(script_name, script_options={}) click to toggle source
# File lib/pushapp/remote.rb, line 30
def script(script_name, script_options={})
  tasks[@event] << Pushapp::Tasks::Script.new(script_name, merge_options(script_options))
end
setup!() click to toggle source

Set up Repositories and Hook

# File lib/pushapp/remote.rb, line 72
def setup!
  run "#{init_repository} && #{setup_repository}"
  Pushapp::Hook.new(self).setup
end
ssh!() click to toggle source
# File lib/pushapp/remote.rb, line 65
def ssh!
  exec "cd #{path} && #{shell_env} $SHELL -l"
end
task(task_name, task_options={}) click to toggle source
# File lib/pushapp/remote.rb, line 34
def task(task_name, task_options={})
  tasks[@event] << config.known_task(task_name).new(merge_options(task_options).merge(task_name: task_name))
end
tasks_on(event) click to toggle source
# File lib/pushapp/remote.rb, line 43
def tasks_on event
  tasks[event.to_s]
end
user() click to toggle source
# File lib/pushapp/remote.rb, line 60
def user
  user = @location.match(/(.*)@/)
  user[1] unless user.nil?
end

Private Instance Methods

init_repository() click to toggle source

Initialize an empty repository

# File lib/pushapp/remote.rb, line 114
def init_repository
  # Instead of git init with a path, so it does not fail on older
  # git versions (https://github.com/effkay/blazing/issues/53)
  "mkdir #{path}; cd #{path} && git init"
end
merge_options(task_options={}) click to toggle source
# File lib/pushapp/remote.rb, line 131
def merge_options task_options={}
  Pushapp.rmerge(options, task_options).merge(remote: self)
end
setup_repository() click to toggle source

Allow pushing to currently checked out branch

# File lib/pushapp/remote.rb, line 123
def setup_repository
  "cd #{path} && git config receive.denyCurrentBranch ignore"
end
shell_env() click to toggle source
# File lib/pushapp/remote.rb, line 127
def shell_env
  env.map {|k,v| "#{k}=\"#{Shellwords.escape(v)}\""}.join(" ")
end