class Object

Public Instance Methods

ask(message, default=true) click to toggle source

Prompts the user for a message to agree/decline

# File lib/helpers.rb, line 62
def ask(message, default=true)
  Capistrano::CLI.ui.agree(message)
end
db_config() click to toggle source
# File lib/recipes/db.rb, line 62
def db_config
  @db_config ||= fetch_db_config
end
docs_path() click to toggle source
# File lib/helpers.rb, line 44
def docs_path
  expanded_path_for('../doc')
end
environment() click to toggle source

automatically sets the environment based on presence of :stage (multistage gem), :rails_env, or RAILS_ENV variable; otherwise defaults to ‘production’

# File lib/helpers.rb, line 7
def environment
  if exists?(:stage)
    stage
  elsif exists?(:rails_env)
    rails_env
  elsif(ENV['RAILS_ENV'])
    ENV['RAILS_ENV']
  else
    "production"
  end
end
expanded_path_for(path) click to toggle source
# File lib/helpers.rb, line 48
def expanded_path_for(path)
  e = File.join(File.dirname(__FILE__),path)
  File.expand_path(e)
end
fetch_db_config() click to toggle source
# File lib/recipes/db.rb, line 66
def fetch_db_config
  require 'yaml'
  file = capture "cat #{shared_path}/config/database.yml"
  db_config = YAML.load(file)
end
generate_config(local_file,remote_file,use_sudo=false) click to toggle source

Generates a configuration file parsing through ERB Fetches local file and uploads it to remote_file Make sure your user has the right permissions.

# File lib/helpers.rb, line 69
def generate_config(local_file,remote_file,use_sudo=false)
  temp_file = '/tmp/' + File.basename(local_file)
  buffer    = parse_config(local_file)
  File.open(temp_file, 'w+') { |f| f << buffer }
  upload temp_file, temp_file, :via => :scp
  run "#{use_sudo ? sudo : ""} mv #{temp_file} #{remote_file}"
  `rm #{temp_file}`
end
is_app_monitored?() click to toggle source
# File lib/helpers.rb, line 31
def is_app_monitored?
  is_using('bluepill', :monitorer) || is_using('god', :monitorer)
end
is_using(something, with_some_var) click to toggle source
# File lib/helpers.rb, line 35
def is_using(something, with_some_var)
 exists?(with_some_var.to_sym) && fetch(with_some_var.to_sym).to_s.downcase == something
end
is_using_nginx() click to toggle source
# File lib/helpers.rb, line 19
def is_using_nginx
  is_using('nginx',:web_server)
end
is_using_passenger() click to toggle source
# File lib/helpers.rb, line 23
def is_using_passenger
  is_using('passenger',:app_server)
end
is_using_unicorn() click to toggle source
# File lib/helpers.rb, line 27
def is_using_unicorn
  is_using('unicorn',:app_server)
end
parse_config(file) click to toggle source
# File lib/helpers.rb, line 53
def parse_config(file)
  require 'erb'  #render not available in Capistrano 2
  template=File.read(file)          # read it
  return ERB.new(template).result(binding)   # parse it
end
prepare_for_db_command() click to toggle source
# File lib/recipes/db.rb, line 98
def prepare_for_db_command
  set :db_name, "#{application}_#{environment}"
  set(:db_admin_user) { Capistrano::CLI.ui.ask "Username with priviledged database access (to create db):" }
  set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" }
  set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" }
end
prepare_from_yaml() click to toggle source

Sets database variables from remote database.yaml

# File lib/recipes/db.rb, line 52
def prepare_from_yaml
  set(:db_file) { "#{application}-dump.sql.bz2" }
  set(:db_remote_file) { "#{shared_path}/backup/#{db_file}" }
  set(:db_local_file)  { "tmp/#{db_file}" }
  set(:db_user) { db_config[rails_env]["username"] }
  set(:db_pass) { db_config[rails_env]["password"] }
  set(:db_host) { db_config[rails_env]["host"] }
  set(:db_name) { db_config[rails_env]["database"] }
end
run_rake(task) click to toggle source

Executes a basic rake task. Example: run_rake log:clear

# File lib/helpers.rb, line 82
def run_rake(task)
  run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
end
templates_path() click to toggle source

Path to where the generators live

# File lib/helpers.rb, line 40
def templates_path
  expanded_path_for('../generators')
end
unicorn_restart_cmd() click to toggle source
# File lib/recipes/unicorn.rb, line 40
def unicorn_restart_cmd
  "kill -USR2 `cat #{unicorn_pid}`"
end
unicorn_start_cmd() click to toggle source
# File lib/recipes/unicorn.rb, line 32
def unicorn_start_cmd
  "cd #{current_path} && #{unicorn_bin} -c #{unicorn_remote_config} -E #{rails_env} -D"
end
unicorn_stop_cmd() click to toggle source
# File lib/recipes/unicorn.rb, line 36
def unicorn_stop_cmd
  "kill -QUIT `cat #{unicorn_pid}`"
end