Class: PactBroker::Matrix::ParseQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/matrix/parse_query.rb

Class Method Summary collapse

Class Method Details

.call(query) ⇒ Object



6
7
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
39
40
# File 'lib/pact_broker/matrix/parse_query.rb', line 6

def self.call query
  params = Rack::Utils.parse_nested_query(query)
  selectors = (params['q'] || []).collect do |i|
    p = {}
    p[:pacticipant_name] = i['pacticipant'] if i['pacticipant'] && i['pacticipant'] != ''
    p[:pacticipant_version_number] = i['version'] if i['version'] && i['version'] != ''
    p[:latest] = true if i['latest'] == 'true'
    p[:tag] = i['tag'] if i['tag'] && i['tag'] != ''
    p
  end
  options = {}
  if params.key?('success') && params['success'].is_a?(Array)
    options[:success] = params['success'].collect do | value |
      value == '' ? nil : value == 'true'
    end
  end
  if params.key?('success') && params['success'].is_a?(String)
    options[:success] = [params['success'] == '' ? nil : params['success'] == 'true']
  end
  if params.key?('latestby') && params['latestby'] != ''
    options[:latestby] = params['latestby']
  end
  if params.key?('limit') && params['limit'] != ''
    options[:limit] = params['limit']
  else
    options[:limit] = "100"
  end
  if params.key?('latest') && params['latest'] != ''
    options[:latest] = params['latest'] == 'true'
  end
  if params.key?('tag') && params['tag'] != ''
    options[:tag] = params['tag']
  end
  return selectors, options
end