Method: Beaker::Options::Validator#check_yaml_file

Defined in:
lib/beaker/options/validator.rb

#check_yaml_file(f, msg = '') ⇒ Object

Determine is a given file exists and is a valid YAML file

Parameters:

  • f (String)

    The YAML file path to examine

  • msg (String) (defaults to: '')

    An options message to report in case of error

Raises:

  • (ArgumentError)

    Raise if file does not exist or is not valid YAML



13
14
15
16
17
18
19
20
21
# File 'lib/beaker/options/validator.rb', line 13

def check_yaml_file(f, msg = '')
  validator_error "#{f} does not exist (#{msg})" unless File.file?(f)

  begin
    YAML.load_file(f)
  rescue Beaker::Options::Parser::PARSE_ERROR => e
    validator_error "#{f} is not a valid YAML file (#{msg})\n\t#{e}"
  end
end