json-merge_patch 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bda345671285245e45dc0666b0ce0e79c15d3950
4
- data.tar.gz: c1b5cd2284d269260896ff5be37e1eda7eba05b9
3
+ metadata.gz: 6ce09ddf6d3610381e68fbb86d8ccf6874573007
4
+ data.tar.gz: 15046d860a25fc45329f784fd3a9a639534be7d2
5
5
  SHA512:
6
- metadata.gz: 19dc0616daa81fa8d9b8de3db0b496a2447ee81325e0a786fca1468ad03c63f9a30e2d733bc4ff4fdc3994d87cfe4bd46119eaa3e33a4315001af47dcb8f0755
7
- data.tar.gz: 60c56930ed226e38e7d7fd5199f3f2e85ff97220a325c2f29e4660f8fd31929e1daa91be87dfbe4e021ce080fe7d30645705ee385e67c7b07acc5769f229993d
6
+ metadata.gz: 3afcecc326503602ae67a18db19bc3d34596543ffe68e57a0284eb22c4b7bb4bbc5d7e2d70b03d8000e7077e0bf5bdd11ef14fd55b266939b5da4f6ee7255641
7
+ data.tar.gz: fadeda3faadfbe333ad0e9da52a0301d17b008936d3a41f46d6345ad1bca05487988947ae7d1208577438bd5e867904b61b3ad6a27547db157cd60b95a408c4d
data/.travis.yml CHANGED
@@ -3,7 +3,5 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - jruby-18mode
7
6
  - jruby-19mode
8
- - rbx-18mode
9
7
  - rbx-19mode
@@ -18,10 +18,19 @@ module JSON
18
18
 
19
19
  if merge_patch.is_a? Hash
20
20
  document.merge!(merge_patch)
21
- document.delete_if {|k, v| v.nil? }
21
+ document.delete_if(&method(:recursive_delete_if))
22
22
  return JSON.dump(document)
23
23
  end
24
- rescue
24
+ rescue
25
25
  raise MergeError
26
26
  end
27
+
28
+ def self.recursive_delete_if(key, value)
29
+ if value.kind_of?(Hash)
30
+ value.delete_if(&method(:recursive_delete_if))
31
+ nil
32
+ else
33
+ value.nil?
34
+ end
35
+ end
27
36
  end
@@ -1,5 +1,5 @@
1
1
  module Json
2
2
  module MergePatch
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -87,6 +87,17 @@ describe "section 2" do
87
87
  provided data whose value is explicitly null is to be treated
88
88
  as if the member were undefined.
89
89
  =end
90
+ describe "object" do
91
+ it "replaces members" do
92
+ document = %q'{"foo":"bar"}'
93
+
94
+ merge_patch = %q'{"foo":"baz"}'
95
+
96
+ expected = %q'{"foo":"baz"}'
97
+
98
+ assert_equal expected, JSON.merge(document, merge_patch)
99
+ end
100
+ end
90
101
  end
91
102
 
92
103
  describe "part 4" do
@@ -98,6 +109,29 @@ describe "section 2" do
98
109
  in the provided data whose value is explicitly null is to be
99
110
  treated as if the member was undefined.
100
111
  =end
112
+ describe "patch has a primitive" do
113
+ it "replaces members" do
114
+ document = %q'{"foo":{"bar":"baz"}}'
115
+
116
+ merge_patch = %q'{"foo":2}'
117
+
118
+ expected = %q'{"foo":2}'
119
+
120
+ assert_equal expected, JSON.merge(document, merge_patch)
121
+ end
122
+ end
123
+
124
+ describe "patch has an array" do
125
+ it "replaces members" do
126
+ document = %q'{"foo":{"bar":"baz"}}'
127
+
128
+ merge_patch = %q'{"foo":["bar"]}'
129
+
130
+ expected = %q'{"foo":["bar"]}'
131
+
132
+ assert_equal expected, JSON.merge(document, merge_patch)
133
+ end
134
+ end
101
135
  end
102
136
 
103
137
  describe "part 5" do
@@ -107,6 +141,27 @@ describe "section 2" do
107
141
  also a JSON object, then recursively apply Rule #2 to each
108
142
  object.
109
143
  =end
144
+ describe "nested objects" do
145
+ it "recursively " do
146
+ document = %q'{"foo":{"bar":"baz"}}'
147
+
148
+ merge_patch = %q'{"foo":{"bar":{"baz":"qux"}}}'
149
+
150
+ expected = %q'{"foo":{"bar":{"baz":"qux"}}}'
151
+
152
+ assert_equal expected, JSON.merge(document, merge_patch)
153
+ end
154
+ end
155
+
156
+ it "recursive removal" do
157
+ document = %q'{"foo":{"bar":"baz"}}'
158
+
159
+ merge_patch = %q'{"foo":{"bar":null}}'
160
+
161
+ expected = %q'{"foo":{}}'
162
+
163
+ assert_equal expected, JSON.merge(document, merge_patch)
164
+ end
110
165
  end
111
166
 
112
167
  describe "part 6" do
@@ -152,7 +207,7 @@ describe "README example" do
152
207
  }
153
208
  JSON
154
209
 
155
- expected = <<-JSON.strip_heredoc.chomp
210
+ expected = <<-JSON.strip_heredoc.gsub(/\s/, "")
156
211
  {
157
212
  "title": "Goodbye!",
158
213
  "author" : {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-merge_patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik