Class: Pact::Message::ConsumerContractParser
- Inherits:
-
Object
- Object
- Pact::Message::ConsumerContractParser
- Includes:
- SymbolizeKeys
- Defined in:
- lib/pact/message/consumer_contract_parser.rb
Instance Method Summary collapse
Instance Method Details
#call(hash) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pact/message/consumer_contract_parser.rb', line 11 def call(hash) hash = symbolize_keys(hash) = { pact_specification_version: pact_specification_version(hash) } interactions = hash[:messages].each_with_index.collect do |hash, index| Pact::ConsumerContract::Message.from_hash({ index: index }.merge(hash), ) end ConsumerContract.new( :consumer => ServiceConsumer.from_hash(hash[:consumer]), :provider => ServiceProvider.from_hash(hash[:provider]), :interactions => interactions ) end |
#can_parse?(hash) ⇒ Boolean
24 25 26 |
# File 'lib/pact/message/consumer_contract_parser.rb', line 24 def can_parse?(hash) hash.key?('messages') || hash.key?(:messages) end |
#pact_specification_version(hash) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/pact/message/consumer_contract_parser.rb', line 28 def pact_specification_version hash # TODO handle all 3 ways of defining this... # metadata.pactSpecificationVersion maybe_pact_specification_version_1 = hash[:metadata] && hash[:metadata]['pactSpecification'] && hash[:metadata]['pactSpecification']['version'] maybe_pact_specification_version_2 = hash[:metadata] && hash[:metadata]['pactSpecificationVersion'] pact_specification_version = maybe_pact_specification_version_1 || maybe_pact_specification_version_2 pact_specification_version ? Pact::SpecificationVersion.new(pact_specification_version) : Pact::SpecificationVersion::NIL_VERSION end |