Module: Oats::Roptions

Defined in:
lib/oats/roptions.rb

Class Method Summary collapse

Class Method Details

.overlay(options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/oats/roptions.rb', line 10

def Roptions.overlay(options)
  opts_array = options['_:options']
  if options['_:json']
    $log.info "Overriding Oats.data with: #{options['_:json']}"
    $oats.deep_merge!(JSON.parse(options['_:json']))
  end
  if opts_array
    opts_array.each do |opt_valu|

      opt, valu = opt_valu.split(/\s*:\s*/)
      data_keys = opt.split('.')
      value = $oats
      until data_keys.size == 1 do
        value = value[key=data_keys.shift]
        Oats.assert value.instance_of?(Hash), "Oats.data #{opt} is not a hash at #{key}"
      end
      $log.info "Option #{opt.inspect} specified as: #{valu.inspect} is overriding #{value[data_keys.first].inspect}"
      value[data_keys.first] = valu
    end
  end
end

.override(options = {}) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/oats/roptions.rb', line 32

def Roptions.override(options={})
  oats_data = $oats
  oats_lib = Util.expand_path(File.dirname(__FILE__)+'/..')
  oats_data['_']['oats_lib'] = oats_lib
  options.each do |key,val|
    data_keys = key.split(':')
    v = oats_data
    key_var = nil
    loop do
      key_var = data_keys.shift
      break if data_keys.empty? or key_var == '_'
      v = v[key_var]
    end
    next if key_var == '_'
    if val.instance_of?(Array)
      val_str = val.join(',')
    else
      val_str = val.to_s
    end
    vval = v[key_var]
    if vval.instance_of?(Array)
      vval_str = vval.join(',')
    else
      vval_str = vval.to_s
    end
    $log.info "Option #{key.inspect} specified as: #{val_str.inspect} is overriding #{vval_str.inspect}"\
      unless $oats_execution['agent']
    v[key_var] = val
  end

  # *** Now verify the options ***
  # Ensure log_level valid
  level = Log4r::Log4rConfig::LogLevels.index(oats_data['execution']['log_level'])
  raise(OatsBadInput, "Unrecognized execution:log_level [#{oats_data['execution']['log_level']}]") unless level
  $log.level = level = 1 if $log

  raise(OatsBadInput,"Must specify execution:dir_results") unless oats_data['execution']['dir_results']

  # Fix path to vendor, needed to run under java
  oats_data['_']['vendor'] = Util.expand_path('../vendor',oats_lib)

  # Verify existence of browser to show results
  oats_data['selenium']['ide']['result_browser'] = oats_data['selenium']['ide']['result_browser']
  oats_data['selenium']['ide']['show_result'] = 0 unless oats_data['selenium']['ide']['show_result']

  unless oats_data['selenium']['pause_on_exit']
    if oats_data['execution']['test_files'] and oats_data['execution']['test_files'].first =~ /\.yml/
      oats_data['selenium']['pause_on_exit'] = 0
    else
      oats_data['selenium']['pause_on_exit'] = 1
    end
  end
  return options
end