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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 894288984c47a8024c8ad9aca1623537133d53b2
4
- data.tar.gz: 988d1ca4d56c52d9e258c70f75e662864c6c8023
3
+ metadata.gz: 9f0f1117607f1ce588b332bf20b2632688b59402
4
+ data.tar.gz: d46da468729687703e46e268464f56f2f93566d4
5
5
  SHA512:
6
- metadata.gz: 02aaa8faef28ac67519dca82810eb0b7d1a44a34550a63e134fc23f4db0710d0074b3ca2123adcafe825d50da7427f0593d7861e2edd4b7619bc0f92c27c2d9f
7
- data.tar.gz: 825104af0dbf0885c2aa9457cd328384a8ecb9c0e4ff2463878b5dbc69b9f17096f1a1bd0ac826445c5b54944cf8190e9686367c6eb59456d604c963dc0bc8c1
6
+ metadata.gz: 6bddcfa86d3e8d8129dc23916b2521397737b111ead9249900e82f216e7d50a5f77b1f3babfdb489d58744813c5ed8d7623144be10596f5752ea0a6953a1c336
7
+ data.tar.gz: 0dc6deeefefa9327a4ecff277ccd254f5ba4df32dd027eb0f8bad0b5f79492a4bf9eb6ed827f40df5a84dcf7f6cb5a3a2e5f0f58fbe64267d423f8f9d5300087
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.2.1'
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'
@@ -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
- value = _scope{ yield self }
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) || value.nil?
264
- value
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
- _merge_values(current_value, value)
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
@@ -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.1
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-07 00:00:00.000000000 Z
12
+ date: 2014-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport