Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#ask(message, default = true) ⇒ Object

Prompts the user for a message to agree/decline



62
63
64
# File 'lib/helpers.rb', line 62

def ask(message, default=true)
  Capistrano::CLI.ui.agree(message)
end

#docs_pathObject



44
45
46
# File 'lib/helpers.rb', line 44

def docs_path
  expanded_path_for('../doc')
end

#environmentObject

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



7
8
9
10
11
12
13
14
15
16
17
# 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) ⇒ Object



48
49
50
51
# File 'lib/helpers.rb', line 48

def expanded_path_for(path)
  e = File.join(File.dirname(__FILE__),path)
  File.expand_path(e)
end

#generate_config(local_file, remote_file) ⇒ Object

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



69
70
71
72
73
74
75
# 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?Boolean

Returns:

  • (Boolean)


31
32
33
# 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) ⇒ Object



35
36
37
# 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_nginxObject



19
20
21
# File 'lib/helpers.rb', line 19

def is_using_nginx
  is_using('nginx',:web_server)
end

#is_using_passengerObject



23
24
25
# File 'lib/helpers.rb', line 23

def is_using_passenger
  is_using('passenger',:app_server)
end

#is_using_unicornObject



27
28
29
# File 'lib/helpers.rb', line 27

def is_using_unicorn
  is_using('unicorn',:app_server)
end

#parse_config(file) ⇒ Object



53
54
55
56
57
# 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

#run_rake(task) ⇒ Object

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



81
82
83
# File 'lib/helpers.rb', line 81

def run_rake(task)
  run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
end

#templates_pathObject

Path to where the generators live



40
41
42
# File 'lib/helpers.rb', line 40

def templates_path
  expanded_path_for('../generators')
end