Class: PactBroker::Pacts::SortContent
- Inherits:
-
Object
- Object
- PactBroker::Pacts::SortContent
- Defined in:
- lib/pact_broker/pacts/sort_content.rb
Class Method Summary collapse
- .call(pact_hash) ⇒ Object
- .order_child_array(array) ⇒ Object
- .order_hash(hash) ⇒ Object
- .order_object(thing) ⇒ Object
- .order_verifiable_content(array) ⇒ Object
- .verifiable_content_key_for(pact_hash) ⇒ Object
Class Method Details
.call(pact_hash) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 6 def self.call pact_hash key = verifiable_content_key_for(pact_hash) if key content = pact_hash[key] sorted_pact_hash = order_object(pact_hash) sorted_pact_hash[key] = order_verifiable_content(content) sorted_pact_hash else pact_hash end end |
.order_child_array(array) ⇒ Object
43 44 45 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 43 def self.order_child_array array array.collect{|thing| order_object(thing) } end |
.order_hash(hash) ⇒ Object
47 48 49 50 51 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 47 def self.order_hash hash hash.keys.sort.each_with_object({}) do | key, new_hash | new_hash[key] = order_object(hash[key]) end end |
.order_object(thing) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 35 def self.order_object thing case thing when Hash then order_hash(thing) when Array then order_child_array(thing) else thing end end |
.order_verifiable_content(array) ⇒ Object
30 31 32 33 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 30 def self.order_verifiable_content array array_with_ordered_hashes = order_object(array) array_with_ordered_hashes.sort{|a, b| a.to_json <=> b.to_json } end |
.verifiable_content_key_for(pact_hash) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/pact_broker/pacts/sort_content.rb', line 19 def self.verifiable_content_key_for pact_hash if pact_hash['interactions'] 'interactions' elsif pact_hash['messages'] 'messages' else nil end end |