jbuilder 2.1.1 → 2.1.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 +4 -4
- data/test/jbuilder_test.rb +20 -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: 076e206930dcf4260390206ed366028320a9b897
|
4
|
+
data.tar.gz: ad02cd2d181c768614d5eb87feedc326ebb9646e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8430c22ceacd53c3b3b26fc762e4e6051cd865b1542d0b38091953a5d2371890ea392a51e675a1d8d0c1fb4bbaa171fecd1d37d95c1448f6bd065a03b98f8875
|
7
|
+
data.tar.gz: 968917e192f36be06d5adf63803bd0a26443f474b29b71716c111cf29df08a283a47044eaef684091ecbd363c36cdf88ac14b5d8d17c4a40e1d3340ecb3a51f1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
2.1.2
|
4
|
+
-----
|
5
|
+
* [Cast array-like objects to array before merging](https://github.com/rails/jbuilder/commit/7b8c8a1cb09b7f3dd26e5643ebbd6b2ec67185db)
|
6
|
+
|
3
7
|
2.1.1
|
4
8
|
-----
|
5
9
|
* [Remove unused file](https://github.com/rails/jbuilder/commit/e49e1047976fac93b8242ab212c7b1a463b70809)
|
data/jbuilder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.1.
|
3
|
+
s.version = '2.1.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
@@ -174,12 +174,14 @@ class Jbuilder
|
|
174
174
|
#
|
175
175
|
# [1,2,3]
|
176
176
|
def array!(collection = [], *attributes, &block)
|
177
|
-
array = if
|
177
|
+
array = if collection.nil?
|
178
|
+
[]
|
179
|
+
elsif block
|
178
180
|
_map_collection(collection, &block)
|
179
181
|
elsif attributes.any?
|
180
182
|
_map_collection(collection) { |element| extract! element, *attributes }
|
181
183
|
else
|
182
|
-
collection
|
184
|
+
collection.to_a
|
183
185
|
end
|
184
186
|
|
185
187
|
merge! array
|
@@ -276,8 +278,6 @@ class Jbuilder
|
|
276
278
|
end
|
277
279
|
|
278
280
|
def _map_collection(collection)
|
279
|
-
return [] if collection.nil?
|
280
|
-
|
281
281
|
collection.map do |element|
|
282
282
|
_scope{ yield element }
|
283
283
|
end
|
data/test/jbuilder_test.rb
CHANGED
@@ -18,6 +18,16 @@ class NonEnumerable
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
class VeryBasicWrapper < BasicObject
|
22
|
+
def initialize(thing)
|
23
|
+
@thing = thing
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(name, *args, &block)
|
27
|
+
@thing.send name, *args, &block
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
21
31
|
# This is not Struct, because structs are Enumerable
|
22
32
|
class Person
|
23
33
|
attr_reader :name, :age
|
@@ -254,6 +264,16 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
254
264
|
assert_equal 'world', result['comments'].second['content']
|
255
265
|
end
|
256
266
|
|
267
|
+
test 'array! casts array-like objects to array before merging' do
|
268
|
+
wrapped_array = VeryBasicWrapper.new(%w[foo bar])
|
269
|
+
|
270
|
+
result = jbuild do |json|
|
271
|
+
json.array! wrapped_array
|
272
|
+
end
|
273
|
+
|
274
|
+
assert_equal %w[foo bar], result
|
275
|
+
end
|
276
|
+
|
257
277
|
test 'nesting multiple children from array with inline loop on root' do
|
258
278
|
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
259
279
|
|
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.1.
|
4
|
+
version: 2.1.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-
|
12
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|