hashdiff_sym 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1c3c20780bd5ac5b4651aa308d5efe2978c1d87
4
- data.tar.gz: 5ed5b1c281805ea581428c5574dc5ff7d93f2237
3
+ metadata.gz: a995af36ade64ace421f4c1f77cbd795503ff396
4
+ data.tar.gz: 5884eee448ee410b475a2e11d2859e53b874db3b
5
5
  SHA512:
6
- metadata.gz: 73de6c8ca7869ea1990376f6e3a4c8daedfe9e16f50e15b920df5efb69f59dc84b2bdb81f920c807fb57e46d53c70209f72ffe00494d81cf1fe83b3c81d68a3b
7
- data.tar.gz: 26ff1285b00bc83824f946e06499a2c2b371969b0149eeb09245d2e41d66930008d626656fa8fc3e2947bf206a307b1a8f28e083cdec29a8c8d03b6e20899e7c
6
+ metadata.gz: a6e5543067e990081a527d7936c2af1116457e797951d6c3b1cc7f05e01ea9a7ba1b8b013f061d53583d81a924cb8404b4c1b0e25eead61f31538f45cbffd2d1
7
+ data.tar.gz: 416125f2896fd4d3736ca30a4de4358c734d71ee337ab096363e93e6564bf7210b1a89ea0601b97d7cbaa612a7fe414aa6e60b27a2ec3cfc2baca0ccf12db734
data/README.md CHANGED
@@ -17,6 +17,16 @@ diff = HashDiffSym.diff(a, b)
17
17
  HashDiffSym.patch!(a, diff).should == b
18
18
  ```
19
19
 
20
+ ## Installing
21
+
22
+ Add this to your Gemfile
23
+
24
+ `gem "hashdiff_sym"`
25
+
26
+ or just run
27
+
28
+ `gem install hashdiff_sym`
29
+
20
30
  ## License
21
31
 
22
32
  HashDiffSym is distributed under the MIT-LICENSE.
@@ -127,7 +127,7 @@ module HashDiffSym
127
127
  added_keys = obj2.keys - obj1.keys
128
128
 
129
129
  # add deleted properties
130
- deleted_keys.sort.each do |k|
130
+ deleted_keys.to_s_sort.each do |k|
131
131
  custom_result = custom_compare(opts[:comparison], "#{prefix}#{export_key(k)}", obj1[k], nil)
132
132
 
133
133
  if custom_result
@@ -138,10 +138,10 @@ module HashDiffSym
138
138
  end
139
139
 
140
140
  # recursive comparison for common keys
141
- common_keys.sort.each {|k| result.concat(diff(obj1[k], obj2[k], opts.merge(:prefix => "#{prefix}#{export_key(k)}"))) }
141
+ common_keys.to_s_sort.each {|k| result.concat(diff(obj1[k], obj2[k], opts.merge(:prefix => "#{prefix}#{export_key(k)}"))) }
142
142
 
143
143
  # added properties
144
- added_keys.sort.each do |k|
144
+ added_keys.to_s_sort.each do |k|
145
145
  unless obj1.key?(k)
146
146
  custom_result = custom_compare(opts[:comparison], "#{prefix}#{export_key(k)}", nil, obj2[k])
147
147
 
@@ -145,3 +145,9 @@ module HashDiffSym
145
145
  end
146
146
  end
147
147
  end
148
+
149
+ class Array
150
+ def to_s_sort
151
+ self.sort { |a, b| a.to_s <=> b.to_s }
152
+ end
153
+ end
@@ -1,3 +1,3 @@
1
1
  module HashDiffSym
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -149,6 +149,11 @@ describe HashDiffSym do
149
149
  diff.should == [['-', 'a.:x', 2], ['-', 'a.:z', 4], ['-', 'b.:x', 3], ["-", "b.:z[0]", 1], ["+", "b.:z[2]", 4], ['+', 'b.:y', 3]]
150
150
  end
151
151
 
152
+ it "should compare hashes with both string and symbols keys" do
153
+ diff = HashDiffSym.diff({}, { :symbol_key => 1, "string_key" => 1})
154
+ diff.should == [["+", "string_key", 1], ["+", ":symbol_key", 1]]
155
+ end
156
+
152
157
  context 'when :numeric_tolerance requested' do
153
158
  it "should be able to diff changes in hash value" do
154
159
  a = {'a' => 0.558, 'b' => 0.0, 'c' => 0.65, 'd' => 'fin'}
@@ -151,4 +151,11 @@ describe HashDiffSym do
151
151
  diff = HashDiffSym.diff(a, b)
152
152
  HashDiffSym.patch!(a, diff).should == b
153
153
  end
154
+
155
+ it "should patch hashes with both symbol and string keys correctly" do
156
+ a = {a: 3, "b" => 4}
157
+ b = {a: {a1: 1, a2: 2}, "b" => 5}
158
+ diff = HashDiffSym.diff(a, b)
159
+ HashDiffSym.patch!(a, diff).should == b
160
+ end
154
161
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashdiff_sym
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Fengyun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-02 00:00:00.000000000 Z
12
+ date: 2016-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec