class Object
Public Instance Methods
ask(message, default=true)
click to toggle source
auth_options()
click to toggle source
# File lib/recipes/db.rb, line 32 def auth_options if db_user && db_pass "-u #{db_user} -p #{db_pass}" end end
db_config()
click to toggle source
# File lib/recipes/db.rb, line 52 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 56 def fetch_db_config require 'yaml' file = capture "cat #{shared_path}/config/mongoid.yml" db_config = YAML.load(file) end
generate_config(local_file,remote_file)
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) temp_file = '/tmp/' + File.basename(local_file) buffer = parse_config(local_file) File.open(temp_file, 'w+') { |f| f << buffer } upload temp_file, remote_file, :via => :scp `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) 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_from_yaml()
click to toggle source
Sets database variables from remote database.yaml
# File lib/recipes/db.rb, line 39 def prepare_from_yaml set(:db_backup_path) { "#{shared_path}/backup/" } set(:db_local_file) { "tmp/" } set(:db_user) { db_config[rails_env.to_s]["username"] } set(:db_pass) { db_config[rails_env.to_s]["password"] } set(:db_host) { db_config[rails_env.to_s]["host"] } set(:db_port) { db_config[rails_env.to_s]["port"] } set(:db_name) { db_config[rails_env.to_s]["database"] } set(:db_remote_backup) { "#{db_backup_path}/#{db_name}" } end
run_rake(task)
click to toggle source
rvmsudo(task)
click to toggle source
# File lib/helpers.rb, line 86 def rvmsudo(task) run "cd #{current_path} && rvmsudo #{task}" 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 {{PID}}" end
unicorn_start_cmd()
click to toggle source
# File lib/recipes/unicorn.rb, line 32 def unicorn_start_cmd "#{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 {{PID}}" end