class Dopi::Command::Ssh::FileContains

Public Instance Methods

file() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 31
def file
  @file ||= file_valid? ? hash[:file] : nil
end
pattern() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 35
def pattern
  @pattern ||= pattern_valid? ?
    hash[:pattern] : nil
end
run() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 22
def run
  cmd_stdout, cmd_stderr, cmd_exit_code = ssh_command({}, command_string)
  check_exit_code(cmd_exit_code)
end
run_noop() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 27
def run_noop
  log(:info, "(NOOP) Executing '#{command_string}' for command #{name}")
end
validate() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 15
def validate
  validate_ssh
  validate_exit_code
  log_validation_method(:file_valid?, CommandParsingError)
  log_validation_method(:pattern_valid?, CommandParsingError)
end

Private Instance Methods

command_string() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 42
def command_string
  "grep -e \"#{pattern}\" #{file}"
end
file_valid?() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 46
def file_valid?
  hash[:file] or
    raise CommandParsingError, "Plugin #{name}: The key 'file' needs to be specified"
  begin
    Pathname.new(hash[:file]).absolute? or
      raise CommandParsingError, "Plugin #{name}: The path for 'file' has to be absolute"
  rescue ArgumentError => e
    raise CommandParsingError, "Plugin #{name}: The value in 'file' is not a valid file path: #{e.message}"
  end
end
pattern_valid?() click to toggle source
# File lib/dopi/command/ssh/file_contains.rb, line 57
def pattern_valid?
  hash[:pattern] or
    raise CommandParsingError, "Plugin #{name}: The key 'pattern' needs to be specified"
  begin
    Regexp.new(hash[:pattern])
  rescue
    raise CommandParsingError, "Plugin #{name}: The value in 'pattern' is not a valid regexp: #{e.message}"
  end
end