Top Level Namespace

Defined Under Namespace

Modules: Yum

Constant Summary collapse

NotificationTasks =

Deployment tasks that need an after hook to notify hoptoad/newrelic/etc.

["deploy", "deploy:migrations", "deploy:cold", "deploy:rollback"]

Instance Method Summary collapse

Instance Method Details

#first_db_hostObject

Returns the first host with the ‘db’ role. (useful for :pull commands)



31
32
33
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 31

def first_db_host
  @db_host ||= find_servers(:roles => :db).map(&:to_s).first
end

#get_with_status(file, dest, options = {}) ⇒ Object

Adds file status to ‘get’ commands



36
37
38
39
40
41
42
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 36

def get_with_status(file, dest, options={})
  last = nil
  get file, dest, options do |channel, name, received, total|
    print "\r      #{name}: #{(Float(received)/total*100).to_i}%"
    print "\n" if received == total
  end
end

#needs_netrc?Boolean

Returns:

  • (Boolean)


32
# File 'lib/crossroads_capistrano/recipes/base.rb', line 32

def needs_netrc?;   repository.include?("code.crossroads.org.hk"); end

#needs_ssh_key?Boolean

Returns:

  • (Boolean)


33
# File 'lib/crossroads_capistrano/recipes/base.rb', line 33

def needs_ssh_key?; repository.include?("github.com"); end

#prompt_with_default(prompt, var, default = nil) ⇒ Object

Helper function which prompts for user input. If user enters nothing, variable is set to the default.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 7

def prompt_with_default(prompt, var, default=nil)
  set(var) do
    # Append default in brackets to prompt if default is not blank.
    if default != "" && !default.nil?
      prompt << " [#{default}]"
    end
    # Keep passwords hidden.
    if prompt.downcase.include?('password')
      Capistrano::CLI.password_prompt("       #{prompt}: ")
    else
      Capistrano::CLI.ui.ask("       #{prompt}: ")
    end
  end
  set var, default if eval("#{var.to_s}.empty?")
end

#rails_versionObject

Detect presence and version of Rails.



24
25
26
27
28
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 24

def rails_version
  return 3 if File.exists?(File.join(fetch(:rails_root), 'script', 'rails'))
  return 2 if File.exists?(File.join(fetch(:rails_root), 'script', 'server'))
  nil
end

#remote_file_exists?(full_path) ⇒ Boolean

Test for presence of file on remote server.

Returns:

  • (Boolean)


45
46
47
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 45

def remote_file_exists?(full_path)
  capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip == 'true'
end

#sed(file, args, char = "@") ⇒ Object

Replaces strings in a file, i.e. @SOME_STRING@ is replaced with ‘replacement’



50
51
52
53
# File 'lib/crossroads_capistrano/recipes/helper_methods.rb', line 50

def sed(file, args, char="@")
  cmd = "sed -i #{file} " << args.map{|k,v|"-e 's%#{char}#{k}#{char}%#{v}%g'"}.join(" ")
  (exists?(:use_sudo) && !use_sudo) ? run(cmd) : sudo(cmd)
end