class Beaker::SedCommand

Public Class Methods

new(platform, expression, filename, opts = {}) click to toggle source

sets up a SedCommand for a particular platform

the purpose is to abstract away platform-dependent details of the sed command

@param [String] platform The host platform string @param [String] expression The sed expression @param [String] filename The file to apply the sed expression to @param [Hash{Symbol=>String}] opts Additional options @option opts [String] :temp_file The temp file to use for in-place substitution

(only applies to solaris hosts, they don't provide the -i option)

@return a new {SedCommand} object

Calls superclass method Beaker::Command::new
# File lib/beaker/command.rb, line 151
def initialize platform, expression, filename, opts = {}
  command = "sed -i -e \"#{expression}\" #{filename}"
  if /solaris|aix|osx|openbsd/.match?(platform)
    command.slice! '-i '
    temp_file = opts[:temp_file] ? opts[:temp_file] : "#{filename}.tmp"
    command << " > #{temp_file} && mv #{temp_file} #{filename} && rm -f #{temp_file}"
  end
  args = []
  opts['ENV'] ||= {}
  super(command, args, opts)
end