Class: Pact::Message::ConsumerContractParser

Inherits:
Object
  • Object
show all
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
# File 'lib/pact/message/consumer_contract_parser.rb', line 11

def call(hash)
  hash = symbolize_keys(hash)
  options = { pact_specification_version: pact_specification_version(hash) }
  interactions = hash[:messages].collect { |hash| Pact::ConsumerContract::Message.from_hash(hash, options)}
  ConsumerContract.new(
    :consumer => ServiceConsumer.from_hash(hash[:consumer]),
    :provider => ServiceProvider.from_hash(hash[:provider]),
    :interactions => interactions
  )
end

#can_parse?(hash) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pact/message/consumer_contract_parser.rb', line 22

def can_parse?(hash)
  hash.key?('messages') || hash.key?(:messages)
end

#pact_specification_version(hash) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/pact/message/consumer_contract_parser.rb', line 26

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