Sha256: 9716f3a0b787305b5fe79602e27056915bc77a9700c0cf3941e993e4d9b61be6

Contents?: true

Size: 1.71 KB

Versions: 42

Compression:

Stored size: 1.71 KB

Contents

require 'rack/utils'
require 'pact_broker/matrix/unresolved_selector'

module PactBroker
  module Matrix
    class ParseQuery
      def self.call query
        params = Rack::Utils.parse_nested_query(query)
        selectors = (params['q'] || []).collect do |i|
          p = PactBroker::Matrix::UnresolvedSelector.new
          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?('days') && params['days'] != ''
          options[:days] = params['days'].to_i
        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

42 entries across 42 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.79.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.78.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.78.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.77.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.76.2 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.76.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.76.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.75.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.74.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.74.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.73.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.72.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.71.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.70.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.69.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.68.1 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.68.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.67.0 lib/pact_broker/matrix/parse_query.rb
pact_broker-2.66.0 lib/pact_broker/matrix/parse_query.rb