-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate general object ordering code from pact specific or…
…dering code
- Loading branch information
Showing
2 changed files
with
28 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'pact_broker/json' | ||
|
||
module PactBroker | ||
module Pacts | ||
class OrderObject | ||
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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters