Class: Pact::ConsumerContract
Constant Summary
Constants included
from PactFile
PactFile::OPEN_TIMEOUT, PactFile::READ_TIMEOUT, PactFile::RETRY_LIMIT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PactFile
#read, #render_pact, #save_pactfile_to_tmp
Methods included from Logging
included, #logger
included, #symbolize_keys
Constructor Details
Returns a new instance of ConsumerContract.
29
30
31
32
33
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 29
def initialize(attributes = {})
@interactions = attributes[:interactions] || []
@consumer = attributes[:consumer]
@provider = attributes[:provider]
end
|
Instance Attribute Details
#consumer ⇒ Object
26
27
28
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 26
def consumer
@consumer
end
|
#interactions ⇒ Object
25
26
27
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 25
def interactions
@interactions
end
|
#provider ⇒ Object
27
28
29
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 27
def provider
@provider
end
|
Class Method Details
.add_parser(consumer_contract_parser) ⇒ Object
35
36
37
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 35
def self.add_parser consumer_contract_parser
parsers.unshift(consumer_contract_parser)
end
|
.from_hash(hash) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 43
def self.from_hash(hash)
parsers.each do | parser |
return parser.call(hash) if parser.can_parse?(hash)
end
raise Pact::UnrecognizePactFormatError.new("This document does not use a recognised Pact format: #{hash}")
end
|
.from_json(string) ⇒ Object
50
51
52
53
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 50
def self.from_json string
deserialised_object = JSON.load(maintain_backwards_compatiblity_with_producer_keys(string))
from_hash(deserialised_object)
end
|
.from_uri(uri, options = {}) ⇒ Object
.maintain_backwards_compatiblity_with_producer_keys(string) ⇒ Object
61
62
63
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 61
def self.maintain_backwards_compatiblity_with_producer_keys string
string.gsub('"producer":', '"provider":').gsub('"producer_state":', '"provider_state":') if string
end
|
Instance Method Details
#each ⇒ Object
79
80
81
82
83
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 79
def each
interactions.each do | interaction |
yield interaction
end
end
|
#find_interaction(criteria) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 65
def find_interaction criteria
interactions = find_interactions criteria
if interactions.size == 0
raise Pact::Error.new("Could not find interaction matching #{criteria} in pact file between #{consumer.name} and #{provider.name}.")
elsif interactions.size > 1
raise Pact::Error.new("Found more than 1 interaction matching #{criteria} in pact file between #{consumer.name} and #{provider.name}.")
end
interactions.first
end
|
#find_interactions(criteria) ⇒ Object
75
76
77
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 75
def find_interactions criteria
interactions.select{ | interaction| interaction.matches_criteria?(criteria)}
end
|
#writable_interactions ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/pact/consumer_contract/consumer_contract.rb', line 85
def writable_interactions
interactions.reject do |interaction|
interaction.respond_to?(:metadata) &&
!interaction.metadata.nil? &&
interaction.metadata.key?(:write_to_pact) &&
interaction.metadata[:write_to_pact] == false
end
end
|