class Pact::Message::ConsumerContractParser

Public Instance Methods

call(hash) click to toggle source
# 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].each_with_index.collect do |hash, index|
    Pact::ConsumerContract::Message.from_hash({ index: index }.merge(hash), options)
  end
  ConsumerContract.new(
    :consumer => ServiceConsumer.from_hash(hash[:consumer]),
    :provider => ServiceProvider.from_hash(hash[:provider]),
    :interactions => interactions
  )
end
can_parse?(hash) click to toggle source
# 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) click to toggle source
# 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