Sha256: a9d0a1652d87d07116a6aeedda8d72939efba22711f9c38017d18cb3df06dac0

Contents?: true

Size: 1.1 KB

Versions: 27

Compression:

Stored size: 1.1 KB

Contents

require "pact_broker/json"
require "pact_broker/pacts/order_hash_keys"

module PactBroker
  module Pacts
    class SortContent
      extend OrderHashKeys

      # TODO handle interactions and messages at the same time
      def self.call pact_hash
        key = verifiable_content_key_for(pact_hash)

        if key
          content = pact_hash[key]
          sorted_pact_hash = order_hash_keys(pact_hash)
          sorted_pact_hash[key] = order_verifiable_content(content)
          sorted_pact_hash
        else
          pact_hash
        end
      end

      def self.verifiable_content_key_for pact_hash
        if pact_hash["interactions"]
          "interactions"
        elsif pact_hash["messages"]
          "messages"
        else
          nil
        end
      end

      def self.order_verifiable_content probably_array
        # You never can tell what people will do...
        if probably_array.is_a?(Array)
          array_with_ordered_hashes = order_hash_keys(probably_array)
          array_with_ordered_hashes.sort_by(&:to_json)
        else
          probably_array
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pact_broker-2.112.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.111.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.109.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.109.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.108.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.107.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.107.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.106.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.105.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.104.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.103.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.102.2 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.102.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.102.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.101.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.100.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.99.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.98.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.97.0 lib/pact_broker/pacts/sort_content.rb