Sha256: 9498c95442f5bcc5a21ffaaad238a3a32e918567e398d67771a4feec447d619c

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

class Capistrano::Configuration

  ##
  # Print an informative message with asterisks.

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

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

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

  ##
  # Run a command and return the result as a string.
  #
  # TODO May not work properly on multiple servers.

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

  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

  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

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
fdlcap-0.4.17 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.15 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.14 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.13 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.12 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.11 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.10 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.9 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.7 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.6 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.5 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.4 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.3 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.2 lib/fdlcap/extensions/configuration.rb
fdlcap-0.4.0 lib/fdlcap/extensions/configuration.rb
fdlcap-0.3.35 lib/fdlcap/extensions/configuration.rb
fdlcap-0.3.34 lib/fdlcap/extensions/configuration.rb
fdlcap-0.3.33 lib/fdlcap/extensions/configuration.rb
fdlcap-0.3.31 lib/fdlcap/extensions/configuration.rb
fdlcap-0.3.30 lib/fdlcap/extensions/configuration.rb