Sha256: 4d35b43f01a2bdb659d35522d73bdd305c3b4a6400128d7c37de5ebc41375b36

Contents?: true

Size: 1.5 KB

Versions: 23

Compression:

Stored size: 1.5 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']
        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
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pact_broker-2.50.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.50.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.49.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.48.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.47.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.47.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.46.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.45.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.44.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.43.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.42.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.41.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.40.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.39.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.38.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.38.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.37.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.36.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.36.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.35.0 lib/pact_broker/matrix/parse_query.rb