Class: PactBroker::Pacts::SortContent

Inherits:
Object
  • Object
show all
Extended by:
OrderHashKeys
Defined in:
lib/pact_broker/pacts/sort_content.rb

Class Method Summary collapse

Methods included from OrderHashKeys

order_child_array, order_hash, order_hash_keys

Class Method Details

.call(pact_hash) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pact_broker/pacts/sort_content.rb', line 9

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

.order_verifiable_content(array) ⇒ Object



32
33
34
35
# File 'lib/pact_broker/pacts/sort_content.rb', line 32

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

.verifiable_content_key_for(pact_hash) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/pact_broker/pacts/sort_content.rb', line 22

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