Sha256: 7803d2ade7c5f7df72b423be1417feeaddd146d1b2ae934a98db0795f3acb16c

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

require 'rack/utils'

module PactBroker
  module Matrix
    class ParseQuery
      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']
        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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pact_broker-2.31.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.30.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.29.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.6 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.5 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.4 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.3 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.2 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.27.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.26.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.26.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.25.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.24.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.23.4 lib/pact_broker/matrix/parse_query.rb