koala 1.6.0 → 1.7.0rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +0,0 @@
1
- # when testing across Ruby versions, we found that JSON string creation inconsistently ordered keys
2
- # which is a problem because our mock testing service ultimately matches strings to see if requests are mocked
3
- # this fix solves that problem by ensuring all hashes are created with a consistent key order every time
4
- module MultiJson
5
- self.use :ok_json
6
-
7
- class << self
8
- def dump_with_ordering(object)
9
- # if it's a hash, recreate it with k/v pairs inserted in sorted-by-key order
10
- # (for some reason, REE fails if we don't assign the ternary result as a local variable
11
- # separately from calling encode_original)
12
- dump_original(sort_object(object))
13
- end
14
-
15
- alias_method :dump_original, :dump
16
- alias_method :dump, :dump_with_ordering
17
-
18
- def load_with_ordering(string)
19
- sort_object(load_original(string))
20
- end
21
-
22
- alias_method :load_original, :load
23
- alias_method :load, :load_with_ordering
24
-
25
- private
26
-
27
- def sort_object(object)
28
- if object.is_a?(Hash)
29
- sort_hash(object)
30
- elsif object.is_a?(Array)
31
- object.collect {|item| item.is_a?(Hash) ? sort_hash(item) : item}
32
- else
33
- object
34
- end
35
- end
36
-
37
- def sort_hash(unsorted_hash)
38
- sorted_hash = KoalaTest::OrderedHash.new(sorted_hash)
39
- unsorted_hash.keys.sort {|a, b| a.to_s <=> b.to_s}.inject(sorted_hash) {|hash, k| hash[k] = unsorted_hash[k]; hash}
40
- end
41
- end
42
- end