Top Level Namespace

Defined Under Namespace

Modules: AlintaTesting, RestClient Classes: Hash

Instance Method Summary collapse

Instance Method Details

#get_url(path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/alinta-testing/overrides.rb', line 33

def get_url(path)
  raise %(Please set an 'endpoint' environment variable provided with the url of the api) unless ENV.key?('endpoint')

  url = ENV['endpoint']
  url = "#{url}/" unless url.end_with?('/')
  url = "#{url}#{@urlbasepath}" unless @urlbasepath.to_s.empty?
  url = "#{url}/" unless url.end_with?('/')
  url = "#{url}#{path}" unless path.empty?
  url
end

#parse_attributes(hashes) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alinta-testing/overrides.rb', line 13

def parse_attributes(hashes)
  hashes.each_with_object({}) do |row, hash|
    name = row['attribute']
    value = row['value']
    type = row['type']
    # this condition is new and allows the value to be resolved from ruby code
    if type == 'expression'
      value = eval(value) 
    else
      value = resolve_functions(value)
      value = resolve(value)
      value.gsub!(/\\n/, "\n")
      value = string_to_type(value, type)
    end
    names = split_fields(name)
    new_hash = names.reverse.inject(value) { |a, n| add_to_hash(a, n) }
    hash.deep_merge!(new_hash) { |_, old, new| new.is_a?(Array) ? merge_arrays(old, new) : new }
  end
end