Sha256: 5487f06188f0d0113dbbcc42f5e78e97608748d8236155465bddf63830c8a117

Contents?: true

Size: 922 Bytes

Versions: 67

Compression:

Stored size: 922 Bytes

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 array
        array_with_ordered_hashes = order_hash_keys(array)
        array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json }
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.79.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.78.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.78.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.77.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.76.2 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.76.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.76.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.75.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.74.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.74.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.73.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.72.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.71.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.70.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.69.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.68.1 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.68.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.67.0 lib/pact_broker/pacts/sort_content.rb
pact_broker-2.66.0 lib/pact_broker/pacts/sort_content.rb