Class: Pact::QueryHash
Constant Summary
Constants included
from Matchers
Matchers::DEFAULT_OPTIONS, Matchers::NO_DIFF, Matchers::NO_DIFF_AT_INDEX
Instance Method Summary
collapse
included, #symbolize_keys
Methods included from Matchers
#diff, #type_diff
#fix_all_the_things, #fix_json_formatting, #fix_regexp, #remove_unicode
Constructor Details
#initialize(query) ⇒ QueryHash
Returns a new instance of QueryHash.
12
13
14
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 12
def initialize query
@hash = query.nil? ? query : convert_to_hash_of_arrays(query)
end
|
Instance Method Details
#==(other) ⇒ Object
32
33
34
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 32
def == other
QueryHash === other && other.query == query
end
|
#as_json(opts = {}) ⇒ Object
20
21
22
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 20
def as_json opts = {}
@hash
end
|
#convert_to_hash_of_arrays(query) ⇒ Object
16
17
18
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 16
def convert_to_hash_of_arrays query
symbolize_keys(query).each_with_object({}) {|(k,v), hash| hash[k] = [*v] }
end
|
#difference(other) ⇒ Object
other will always be a QueryString, not a QueryHash, as it will have ben created from the actual query string.
38
39
40
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 38
def difference(other)
diff(query, symbolize_keys(CGI::parse(other.query)), allow_unexpected_keys: false)
end
|
#empty? ⇒ Boolean
50
51
52
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 50
def empty?
@hash && @hash.empty?
end
|
#eql?(other) ⇒ Boolean
28
29
30
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 28
def eql? other
self == other
end
|
#query ⇒ Object
42
43
44
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 42
def query
@hash
end
|
#to_json(opts = {}) ⇒ Object
24
25
26
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 24
def to_json opts = {}
as_json(opts).to_json(opts)
end
|
#to_s ⇒ Object
46
47
48
|
# File 'lib/pact/consumer_contract/query_hash.rb', line 46
def to_s
@hash.inspect
end
|