jbuilder 2.2.0 → 2.2.1

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: 141e8a9ebdb989259856973050722aae336d7b50
4
- data.tar.gz: 265721f5266ccb8e444a291f04193ac562076abf
3
+ metadata.gz: 894288984c47a8024c8ad9aca1623537133d53b2
4
+ data.tar.gz: 988d1ca4d56c52d9e258c70f75e662864c6c8023
5
5
  SHA512:
6
- metadata.gz: dd8f8b1bfdfff3270bd1abaee9e1248aa202779804997237633ac9fc5bbb08e33e4b9a1910e633bfeab12b3dbef0e5c21084dddf7f47d6030a8b1d52c44f7317
7
- data.tar.gz: 299d5d6f3a75b3bba2f9c666031655ae0813273ea38584d3f410353dae8912dc4d2767e3f0e8092ed34470ff6464a1061e80396a9a4befd79b57ac7cdb308d0b
6
+ metadata.gz: 02aaa8faef28ac67519dca82810eb0b7d1a44a34550a63e134fc23f4db0710d0074b3ca2123adcafe825d50da7427f0593d7861e2edd4b7619bc0f92c27c2d9f
7
+ data.tar.gz: 825104af0dbf0885c2aa9457cd328384a8ecb9c0e4ff2463878b5dbc69b9f17096f1a1bd0ac826445c5b54944cf8190e9686367c6eb59456d604c963dc0bc8c1
data/.travis.yml CHANGED
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.1
4
+ - 1.9
5
+ - 2.0
6
+ - 2.1
7
+ - 2.2
8
+ - ruby-head
7
9
  - jruby-19mode
8
10
  - rbx
9
11
 
@@ -16,8 +18,10 @@ gemfile:
16
18
 
17
19
  matrix:
18
20
  allow_failures:
21
+ - rvm: 2.2
19
22
  - rvm: jruby-19mode
20
23
  - rvm: rbx
24
+ - rvm: ruby-head
21
25
  fast_finish: true
22
26
 
23
27
  notifications:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ 2.2.1
4
+ -----
5
+ * [Fix empty block handling](https://github.com/rails/jbuilder/commit/972a11141403269e9b17b45b0c95f8a9788245ee)
6
+
3
7
  2.2.0
4
8
  -----
5
9
  * [Allow to skip `array!` iterations by calling `next`](https://github.com/rails/jbuilder/commit/81a63308fb9d5002519dd871f829ccc58067251a)
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.0'
3
+ s.version = '2.2.1'
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
@@ -25,7 +25,7 @@ class Jbuilder
25
25
 
26
26
  def set!(key, value = BLANK, *args, &block)
27
27
  result = if block
28
- if BLANK != value
28
+ if !_blank?(value)
29
29
  # json.comments @post.comments { |comment| ... }
30
30
  # { "comments": [ { ... }, { ... } ] }
31
31
  _scope{ array! value, &block }
@@ -253,14 +253,18 @@ class Jbuilder
253
253
  end
254
254
 
255
255
  def _merge_block(key, &block)
256
- current_value = _read(key, {})
256
+ current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK)
257
257
  raise NullError.build(key) if current_value.nil?
258
+
258
259
  value = _scope{ yield self }
259
- value.nil? ? value : _merge_values(current_value, value)
260
- end
261
260
 
262
- def _read(key, default = nil)
263
- _blank? ? default : @attributes.fetch(_key(key)){ default }
261
+ if _blank?(value)
262
+ current_value
263
+ elsif _blank?(current_value) || value.nil?
264
+ value
265
+ else
266
+ _merge_values(current_value, value)
267
+ end
264
268
  end
265
269
 
266
270
  def _write(key, value)
@@ -275,6 +279,7 @@ class Jbuilder
275
279
  def _set_value(key, value)
276
280
  raise NullError.build(key) if @attributes.nil?
277
281
  return if @ignore_nil && value.nil?
282
+ return if _blank?(value)
278
283
  _write key, value
279
284
  end
280
285
 
@@ -310,8 +315,8 @@ class Jbuilder
310
315
  attributes
311
316
  end
312
317
 
313
- def _blank?
314
- BLANK == @attributes
318
+ def _blank?(value=@attributes)
319
+ BLANK == value
315
320
  end
316
321
  end
317
322
 
@@ -131,6 +131,17 @@ class JbuilderTest < ActiveSupport::TestCase
131
131
  assert_equal 32, result['author']['age']
132
132
  end
133
133
 
134
+ test 'empty block handling' do
135
+ result = jbuild do |json|
136
+ json.foo 'bar'
137
+ json.author do
138
+ end
139
+ end
140
+
141
+ assert_equal 'bar', result['foo']
142
+ assert !result.key?('author')
143
+ end
144
+
134
145
  test 'blocks are additive' do
135
146
  result = jbuild do |json|
136
147
  json.author do
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.0
4
+ version: 2.2.1
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-06 00:00:00.000000000 Z
12
+ date: 2014-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport