Sha256: 94892b605cdef015a7b191e6e6e8bfb2bec0819fd46c42c277cda7e405a19de2

Contents?: true

Size: 1.53 KB

Versions: 35

Compression:

Stored size: 1.53 KB

Contents

require 'pact/specification_version'

module Pact
  class HttpConsumerContractParser
    include SymbolizeKeys

    def call(hash)
      hash = symbolize_keys(hash)
      v = pact_specification_version(hash)
      options = { pact_specification_version: v }

      if v.after? 3
        Pact.configuration.error_stream.puts "WARN: This code only knows how to parse v3 pacts, attempting to parse v#{options[:pact_specification_version]} pact using v3 code."
      end

      interactions = hash[:interactions].each_with_index.collect { |hash, index| Interaction.from_hash({ index: index }.merge(hash), options) }
      ConsumerContract.new(
        :consumer => ServiceConsumer.from_hash(hash[:consumer]),
        :provider => ServiceProvider.from_hash(hash[:provider]),
        :interactions => interactions
      )
    end

    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

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

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
pact-support-1.21.2 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.21.1 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.21.0 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.20.2 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.20.1 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.20.0 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.19.0 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.18.1 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.18.0 lib/pact/consumer_contract/http_consumer_contract_parser.rb
hs-pact-support-1.17.1 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.17.0 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.10 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.9 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.8 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.7 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.6 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.5 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.4 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.3 lib/pact/consumer_contract/http_consumer_contract_parser.rb
pact-support-1.16.2 lib/pact/consumer_contract/http_consumer_contract_parser.rb