Class: Capistrano::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/fdlcap/extensions/configuration.rb,
lib/fdlcap/recipes/rsync.rb

Instance Method Summary collapse

Instance Method Details

#check(cmd, options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fdlcap/extensions/configuration.rb', line 44

def check(cmd, options)
  puts cmd
  puts options
  success = false
  if options[:check_exit_code]
    command = "#{cmd}; if [ $? = 0 ]; then echo pass; else echo fail; fi"

  else
    command = "if [#{cmd}]; then echo pass; else echo fail; fi"
  end
  invoke_command(command, options) do |ch, stream, out|
    warn "#{ch[:server]}: #{out}" if stream == :err
    success = out.strip == 'pass' ? true : false
    break if stream == :err
  end
  success
end

#execute(command, failure_message = "Command failed") ⇒ Object



2
3
4
5
# File 'lib/fdlcap/recipes/rsync.rb', line 2

def execute(command, failure_message = "Command failed")
  puts "Executing: #{command}"
  system(command) || raise(failure_message)
end

#inform(message) ⇒ Object

Print an informative message with asterisks.



6
7
8
9
10
# File 'lib/fdlcap/extensions/configuration.rb', line 6

def inform(message)
  puts "#{'*' * (message.length + 4)}"
  puts "* #{message} *"
  puts "#{'*' * (message.length + 4)}"
end

#render_erb_template(filename) ⇒ Object

Read a file and evaluate it as an ERB template. Path is relative to this file’s directory.



16
17
18
19
# File 'lib/fdlcap/extensions/configuration.rb', line 16

def render_erb_template(filename)
  template = File.read(filename)
  result = ERB.new(template).result(binding)
end

#run_and_return(cmd) ⇒ Object

Run a command and return the result as a string.

TODO May not work properly on multiple servers.



26
27
28
29
30
31
32
# File 'lib/fdlcap/extensions/configuration.rb', line 26

def run_and_return(cmd)
  output = []
  run cmd do |ch, st, data|
    output << data
  end
  return output.to_s
end

#try(command, options) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/fdlcap/extensions/configuration.rb', line 34

def try(command, options)
  success = true
  invoke_command(command, options) do |ch, stream, out|
    warn "#{ch[:server]}: #{out}" if stream == :err
    yield ch, stream, out if block_given?
  end
rescue Capistrano::CommandError => e
  success = false
end