Top Level Namespace

Defined Under Namespace

Modules: Capistrano

Instance Method Summary collapse

Instance Method Details

#act_as(name, &block) ⇒ Object



1
2
3
4
5
6
# File 'lib/capistrano/elobuff/helpers.rb', line 1

def act_as(name, &block)
  normal_user = user
  set :user, name.to_s
  yield
  set :user, normal_user
end

#die(why) ⇒ Object



1
2
3
4
5
6
# File 'lib/capistrano/elobuff/ec2/helpers.rb', line 1

def die(why)
  $stdout.sync = true
  puts ""
  puts "  FATAL ERROR: #{why}"
  exit 1
end

#find_ec2_serversObject



8
9
10
11
12
13
14
15
16
# File 'lib/capistrano/elobuff/ec2/helpers.rb', line 8

def find_ec2_servers
  if ids = ENV["SERVERS"]
    ids.split(",").map {|id| ec2.find_server id }
  elsif id = ENV["SERVER"]
    Array(ec2.find_server id)
  else
    die "Please specify SERVER or SERVERS"
  end
end

#require_settings(*methods) ⇒ Object



27
28
29
30
31
# File 'lib/capistrano/elobuff/helpers.rb', line 27

def require_settings(*methods)
  methods.each do |method|
    set_default(method.to_sym) { raise "Please set #{method} "}
  end
end

#runtime_environment_exportsObject



8
9
10
11
12
13
14
15
16
# File 'lib/capistrano/elobuff/helpers.rb', line 8

def runtime_environment_exports
  file = "deploy/#{env}/env"
  raise "Missing deployment file: #{file}" unless File.exists?(file)

  File.read(file).split("\n").map do |line|
    k, v = line.split("=")
    %Q(export #{k}="#{v}";)
  end.join(" ")
end

#set_default(name, *args, &block) ⇒ Object



33
34
35
36
37
# File 'lib/capistrano/elobuff/helpers.rb', line 33

def set_default(name, *args, &block)
  unless exists?(name)
    set(name, *args, &block)
  end
end

#upload_template(template_name, destination) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/capistrano/elobuff/helpers.rb', line 18

def upload_template(template_name, destination)
  file = "deploy/#{env}/#{template_name}.erb"
  raise "Missing deployment file: #{file}" unless File.exists?(file)

  erb = File.read(file)
  result = ERB.new(erb).result(binding)
  put result, destination
end