Permalink
Browse files

removed deep array comparison and sorting.

  • Loading branch information...
1 parent 32d4bd3 commit 7435dfc436ee91cc481770833c502d906f1bfe3e @kirtfitzpatrick kirtfitzpatrick committed Jan 30, 2013
Showing with 2 additions and 41 deletions.
  1. +1 −24 lib/health_inspector/pairing.rb
  2. +1 −1 lib/health_inspector/version.rb
  3. +0 −16 spec/spec_helper.rb
@@ -53,48 +53,25 @@ def stringify_item(item)
if item.kind_of?(Hash)
stringify_hash_keys(item)
elsif item.kind_of?(Array)
- mapped = item.map {|array_item| stringify_item(array_item) }
- mapped.sort {|a,b| heterogeneous_sort(a,b)}
+ item.map {|array_item| stringify_item(array_item) }
else # must be a string
item
end
end
- def heterogeneous_sort(a, b)
- a_class = a.class.to_s
- b_class = b.class.to_s
-
- if a.kind_of?(Hash) && b.kind_of?(Hash)
- a.keys.sort.join <=> b.keys.sort.join
- elsif a_class == b_class
- return a <=> b
- else
- return a_class <=> b_class
- end
- end
-
def recursive_diff(original, other)
if original.kind_of?(Hash) && other.kind_of?(Hash)
(original.keys + other.keys).uniq.inject({}) do |memo, key|
unless original[key] == other[key]
if original[key].kind_of?(Hash) && other[key].kind_of?(Hash)
diff = recursive_diff(original[key], other[key])
memo[key] = diff unless diff.empty?
- elsif original[key].kind_of?(Array) && other[key].kind_of?(Array) && original.size == other.size
- all_diffs = []
- original.each_index do |idx|
- diff = recursive_diff(original[idx], other[idx])
- all_diffs << diff unless diff.nil? || diff.empty?
- end
- memo[key] = all_diffs
else
memo[key] = {"server" => original[key], "local" => other[key]}
end
end
memo
end
- else
- return original == other
end
end
end
@@ -1,3 +1,3 @@
module HealthInspector
- VERSION = "0.6.1"
+ VERSION = "0.6.2"
end
View
@@ -86,14 +86,6 @@ def health_inspector_context
pairing.errors.should be_empty
end
- it "should detect if matching arrays are the same" do
- pairing.server = {"foo" => ["bar", "fizz"]}
- pairing.local = {"foo" => ["fizz", "bar"]}
- pairing.validate
-
- pairing.errors.should be_empty
- end
-
it "should detect if matching arrays with hashes are the same" do
pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
pairing.local = {"foo" => ["bar", {"fizz" => "buzz"}]}
@@ -102,14 +94,6 @@ def health_inspector_context
pairing.errors.should be_empty
end
- it "should detect if matching arrays with hashes are the same even if misordered" do
- pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
- pairing.local = {"foo" => [{"fizz" => "buzz"}, "bar"]}
- pairing.validate
-
- pairing.errors.should be_empty
- end
-
it "should detect if matching arrays with hashes containing symbols/strings are the same" do
pairing.server = {"foo" => ["bar", {"fizz" => "buzz"}]}
pairing.local = {"foo" => ["bar", {:fizz => "buzz"}]}

0 comments on commit 7435dfc

Please sign in to comment.