Top Level Namespace

Defined Under Namespace

Modules: AlintaTesting, RestClient Classes: Hash

Instance Method Summary collapse

Instance Method Details

#get_url(path) ⇒ Object



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

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

#get_url_internal(path, endpoint, urlbasepath, apiversion) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/alinta-testing/overrides/get_url.rb', line 8

def get_url_internal(path, endpoint, urlbasepath, apiversion)
  # remove leading and trailing slashes

  path = path.gsub(/^\/?(.*)\/?$/, '\1')

  if urlbasepath.to_s.empty?
      splitpath = path.split('/')
      basepath =  splitpath.first()
      path = splitpath.drop(1).join('/')
  else
      basepath = urlbasepath
  end
  
  # base end point for all calls

  url = endpoint
  url = "#{url}/" unless url.end_with?('/')

  # common sub-path for this feature

  url = "#{url}#{basepath}" unless basepath.to_s.empty?
  url = "#{url}/" unless url.end_with?('/')

  # versioned route for UAT environments

  version = apiversion
  url = "#{url}#{version}" unless version.to_s.empty?
  url = "#{url}/" unless url.end_with?('/')

  # final path for this request

  url = "#{url}#{path}" unless path.empty?
  url = "#{url}/" unless url.end_with?('/')

  url
end

#parse_attributes(hashes) ⇒ Object



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

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