Sha256: 0f5ab7b0a885b8b869e3539030b7c4b9a248c3a09f4375e5721cd058ae271eba

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

require 'pact/shared/active_support_support'
require 'pact/matchers'
require 'pact/symbolize_keys'

module Pact
  class QueryHash

    include ActiveSupportSupport
    include Pact::Matchers
    include SymbolizeKeys

    def initialize query
      @hash = query.nil? ? query : convert_to_hash_of_arrays(query)
    end

    def convert_to_hash_of_arrays query
      symbolize_keys(query).each_with_object({}) {|(k,v), hash| hash[k] = [*v] }
    end

    def as_json opts = {}
      @hash
    end

    def to_json opts = {}
      as_json(opts).to_json(opts)
    end

    def eql? other
      self == other
    end

    def == other
      QueryHash === other && other.query == query
    end

    # other will always be a QueryString, not a QueryHash, as it will have ben created
    # from the actual query string.
    def difference(other)
      diff(query, symbolize_keys(CGI::parse(other.query)), allow_unexpected_keys: false)
    end

    def query
      @hash
    end

    def to_s
      @hash.inspect
    end

    def empty?
      @hash && @hash.empty?
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pact-support-0.5.4 lib/pact/consumer_contract/query_hash.rb
pact-support-0.5.3 lib/pact/consumer_contract/query_hash.rb
pact-support-0.5.1 lib/pact/consumer_contract/query_hash.rb
pact-support-0.5.0 lib/pact/consumer_contract/query_hash.rb
pact-support-0.4.4 lib/pact/consumer_contract/query_hash.rb
pact-support-0.4.3 lib/pact/consumer_contract/query_hash.rb
pact-support-0.4.2 lib/pact/consumer_contract/query_hash.rb
pact-support-0.4.1 lib/pact/consumer_contract/query_hash.rb
pact-support-0.4.0 lib/pact/consumer_contract/query_hash.rb
pact-support-0.3.1 lib/pact/consumer_contract/query_hash.rb
pact-support-0.3.0 lib/pact/consumer_contract/query_hash.rb
pact-support-0.2.1 lib/pact/consumer_contract/query_hash.rb
pact-support-0.1.4 lib/pact/consumer_contract/query_hash.rb
pact-support-0.2.0 lib/pact/consumer_contract/query_hash.rb
pact-support-0.1.3 lib/pact/consumer_contract/query_hash.rb
pact-support-0.1.2 lib/pact/consumer_contract/query_hash.rb
pact-support-0.1.1 lib/pact/consumer_contract/query_hash.rb