Sha256: 024cafbc11108f003636c18541879807ca1d4c343179e14710cd2dc82a7a804c

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

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

module PactBroker
  module Pacts
    class SortContent
      extend OrderHashKeys

      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{ |a, b| a.to_json <=> b.to_json }
        else
          probably_array
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pact_broker-2.88.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.87.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.86.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.85.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.85.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.84.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.83.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.82.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.81.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.80.0 lib/pact_broker/pacts/sort_content.rb