Class: FileConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/options_parser.rb

Constant Summary collapse

FALSY_VALUE_PATTERN =
/\A(false|no|0)\Z/i

Class Method Summary collapse

Class Method Details

.falsy?(value) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/hiptest-publisher/options_parser.rb', line 42

def self.falsy?(value)
  FALSY_VALUE_PATTERN.match(value)
end

.update_options(options, reporter) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hiptest-publisher/options_parser.rb', line 18

def self.update_options(options, reporter)
  config = ParseConfig.new(options.config)
  config.get_params.each do |param|
    next if options.__cli_args && options.__cli_args.include?(param.to_sym)
    if param.start_with?("no_")
      value = falsy?(config[param]) ? "true" : "false"
      param = param.sub("no_", "")
    else
      value = config[param]
    end
    if falsy?(value)
      options[param] = false
    else
      options[param] = value
    end
    if %w(overriden_templates output_directory).include?(param)
      update_path!(param, config, options)
    end
    options.__config_args << param.to_sym if options.__config_args
  end
rescue => err
  reporter.dump_error(err)
end

.update_path!(param, config, options) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/hiptest-publisher/options_parser.rb', line 46

def self.update_path!(param, config, options)
  path = Pathname.new(config[param])
  return unless path.relative?
  config_path = Pathname.new(options.config)
  config_absolute_path = config_path.relative? ? Pathname.pwd + config_path : config_path
  resolved_path = config_absolute_path.cleanpath.dirname + path
  options[param] = resolved_path.cleanpath.to_path
end