Module: PactBroker::Pacts::OrderHashKeys

Included in:
GenerateInteractionSha, SortContent
Defined in:
lib/pact_broker/pacts/order_hash_keys.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(thing) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/pact_broker/pacts/order_hash_keys.rb', line 6

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

.order_child_array(array) ⇒ Object



14
15
16
# File 'lib/pact_broker/pacts/order_hash_keys.rb', line 14

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

.order_hash(hash) ⇒ Object



18
19
20
21
22
# File 'lib/pact_broker/pacts/order_hash_keys.rb', line 18

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

Instance Method Details

#order_hash_keys(thing) ⇒ Object



24
25
26
# File 'lib/pact_broker/pacts/order_hash_keys.rb', line 24

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