Sha256: 8fab90672063053eecdc3a9d56d3c72b455c13f828e5704f740fa492f0cdd06c

Contents?: true

Size: 618 Bytes

Versions: 44

Compression:

Stored size: 618 Bytes

Contents

require "pact_broker/json"

module PactBroker
  module Pacts
    module OrderHashKeys
      def self.call thing
        case thing
          when Hash then order_hash(thing)
          when Array then order_child_array(thing)
        else thing
        end
      end

      def self.order_child_array array
        array.collect{ |thing| call(thing) }
      end

      def self.order_hash hash
        hash.keys.sort.each_with_object({}) do | key, new_hash |
          new_hash[key] = call(hash[key])
        end
      end

      def order_hash_keys(thing)
        OrderHashKeys.call(thing)
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
pact_broker-2.83.0 lib/pact_broker/pacts/order_hash_keys.rb
pact_broker-2.82.0 lib/pact_broker/pacts/order_hash_keys.rb
pact_broker-2.81.0 lib/pact_broker/pacts/order_hash_keys.rb
pact_broker-2.80.0 lib/pact_broker/pacts/order_hash_keys.rb