module Capistrano::Slnky::Helpers

Public Instance Methods

deploy_user() click to toggle source
# File lib/capistrano/slnky/helpers.rb, line 30
def deploy_user
  capture :id, '-un'
end
file_exists?(path) click to toggle source
# File lib/capistrano/slnky/helpers.rb, line 26
def file_exists?(path)
  test "[ -e #{path} ]"
end
sudo_upload!(from, to) click to toggle source
# File lib/capistrano/slnky/helpers.rb, line 34
def sudo_upload!(from, to)
  filename = File.basename(to)
  to_dir = File.dirname(to)
  tmp_file = "#{fetch(:tmp_dir)}/#{filename}"
  upload! from, tmp_file
  sudo :mv, tmp_file, to_dir
end
template(template_name, locals = {}) click to toggle source

renders the ERB template specified by template_name to a StringIO buffer

# File lib/capistrano/slnky/helpers.rb, line 22
def template(template_name, locals = {})
  StringIO.new(template_to_s(template_name, locals))
end
template_to_s(template_name, locals = {}) click to toggle source

stolen from: github.com/capistrano-plugins/capistrano-unicorn-nginx/blob/e2e0dc17766ce6312a27eb5af52d521d9f6fb8ca/lib/capistrano/unicorn_nginx/helpers.rb

renders the ERB template specified by template_name to string. Use the locals variable to pass locals to the ERB template

# File lib/capistrano/slnky/helpers.rb, line 11
def template_to_s(template_name, locals = {})
  config_file = "#{fetch(:templates_path)}/#{template_name}"
  # if no customized file, proceed with default
  unless File.exists?(config_file)
    config_file = File.join(File.dirname(__FILE__), "templates/#{template_name}")
  end

  ERB.new(File.read(config_file), nil, '-').result(ERBNamespace.new(locals).get_binding)
end