jbuilder 2.2.1 → 2.2.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/jbuilder.gemspec +1 -1
- data/lib/jbuilder.rb +13 -19
- data/test/jbuilder_test.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f0f1117607f1ce588b332bf20b2632688b59402
|
4
|
+
data.tar.gz: d46da468729687703e46e268464f56f2f93566d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bddcfa86d3e8d8129dc23916b2521397737b111ead9249900e82f216e7d50a5f77b1f3babfdb489d58744813c5ed8d7623144be10596f5752ea0a6953a1c336
|
7
|
+
data.tar.gz: 0dc6deeefefa9327a4ecff277ccd254f5ba4df32dd027eb0f8bad0b5f79492a4bf9eb6ed827f40df5a84dcf7f6cb5a3a2e5f0f58fbe64267d423f8f9d5300087
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
2.2.2
|
4
|
+
-----
|
5
|
+
* [Fix `Jbuilder#merge!` inside block](https://github.com/rails/jbuilder/commit/a7b328552eb0d36315f75bff813bea7eecf8c1d7)
|
6
|
+
|
3
7
|
2.2.1
|
4
8
|
-----
|
5
9
|
* [Fix empty block handling](https://github.com/rails/jbuilder/commit/972a11141403269e9b17b45b0c95f8a9788245ee)
|
data/jbuilder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.2.
|
3
|
+
s.version = '2.2.2'
|
4
4
|
s.authors = ['David Heinemeier Hansson', 'Pavel Pravosud']
|
5
5
|
s.email = ['david@37signals.com', 'pavel@pravosud.com']
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
data/lib/jbuilder.rb
CHANGED
@@ -255,18 +255,25 @@ class Jbuilder
|
|
255
255
|
def _merge_block(key, &block)
|
256
256
|
current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK)
|
257
257
|
raise NullError.build(key) if current_value.nil?
|
258
|
+
new_value = _scope{ yield self }
|
259
|
+
_merge_values(current_value, new_value)
|
260
|
+
end
|
258
261
|
|
259
|
-
|
260
|
-
|
261
|
-
if _blank?(value)
|
262
|
+
def _merge_values(current_value, updates)
|
263
|
+
if _blank?(updates)
|
262
264
|
current_value
|
263
|
-
elsif _blank?(current_value) ||
|
264
|
-
|
265
|
+
elsif _blank?(current_value) || updates.nil?
|
266
|
+
updates
|
267
|
+
elsif ::Array === updates
|
268
|
+
current_value = ::Array === current_value ? current_value.dup : []
|
269
|
+
current_value.concat updates
|
265
270
|
else
|
266
|
-
|
271
|
+
current_value = current_value.dup
|
272
|
+
current_value.update updates
|
267
273
|
end
|
268
274
|
end
|
269
275
|
|
276
|
+
|
270
277
|
def _write(key, value)
|
271
278
|
@attributes = {} if _blank?
|
272
279
|
@attributes[_key(key)] = value
|
@@ -302,19 +309,6 @@ class Jbuilder
|
|
302
309
|
value.respond_to?(:map)
|
303
310
|
end
|
304
311
|
|
305
|
-
def _merge_values(attributes, hash_or_array)
|
306
|
-
attributes = attributes.dup
|
307
|
-
|
308
|
-
if ::Array === hash_or_array
|
309
|
-
attributes = [] unless ::Array === attributes
|
310
|
-
attributes.concat hash_or_array
|
311
|
-
else
|
312
|
-
attributes.update hash_or_array
|
313
|
-
end
|
314
|
-
|
315
|
-
attributes
|
316
|
-
end
|
317
|
-
|
318
312
|
def _blank?(value=@attributes)
|
319
313
|
BLANK == value
|
320
314
|
end
|
data/test/jbuilder_test.rb
CHANGED
@@ -157,6 +157,24 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
157
157
|
assert_equal 32, result['author']['age']
|
158
158
|
end
|
159
159
|
|
160
|
+
test 'support merge! method' do
|
161
|
+
result = jbuild do |json|
|
162
|
+
json.merge! 'foo' => 'bar'
|
163
|
+
end
|
164
|
+
|
165
|
+
assert_equal 'bar', result['foo']
|
166
|
+
end
|
167
|
+
|
168
|
+
test 'support merge! method in a block' do
|
169
|
+
result = jbuild do |json|
|
170
|
+
json.author do
|
171
|
+
json.merge! 'name' => 'Pavel'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
assert_equal 'Pavel', result['author']['name']
|
176
|
+
end
|
177
|
+
|
160
178
|
test 'blocks are additive via extract syntax' do
|
161
179
|
person = Person.new('Pavel', 27)
|
162
180
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|