jbuilder 1.4.0 → 1.4.1
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 +15 -0
- data/README.md +1 -1
- data/jbuilder.gemspec +1 -1
- data/lib/jbuilder.rb +34 -26
- data/test/jbuilder_test.rb +14 -16
- metadata +15 -22
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjJiMmFlM2Y1OTVhZjU3MTY2YmRjZTM5ODE0ZGNmMmRmOTEyMWQ1OA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2MxMGNkZjE5YzQ0MTUxYjM4MDNjNzIxMTc0MWM5NmNlOTYzNjY5OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzRhMjZmNThhYzcxN2M2YzJhOWJlODUyNzgzNWVlNDcxOGFlZTMxMzc5MzM3
|
10
|
+
MTljYjhkODA1MGVmYTY2ZmExNTU1YTA2ZTEzOGFlNjkxN2Y4NjkzM2M3Njg1
|
11
|
+
YzE2ZjUwMDQ2ODYyNTljMzYxZDMwYTI0MmY0YmQ3ZjFkYWY0NGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2EyZjUwZWIzNDAzYWY1ZWE3Y2NjMWFkYThkM2RhNTczYzI5NGM5NzhkN2Yw
|
14
|
+
OWU4OTQ0ZjQwYWZiYzA0ZTVkYmFiODU0YWM4YjNmOWUxYjE4MTAwZTUyYzhl
|
15
|
+
N2EyYjU5YzhiODY2NjgzZTg5NmQzNjAyNDA3Mzc2ZWFmYjE5YTQ=
|
data/README.md
CHANGED
@@ -133,7 +133,7 @@ if current_user.admin?
|
|
133
133
|
end
|
134
134
|
|
135
135
|
# You can use partials as well. The following line will render the file
|
136
|
-
# RAILS_ROOT/app/views/api/comments/_comments, and set a local variable
|
136
|
+
# RAILS_ROOT/app/views/api/comments/_comments.json.jbuilder, and set a local variable
|
137
137
|
# 'comments' with all this message's comments, which you can use inside
|
138
138
|
# the partial.
|
139
139
|
json.partial! 'api/comments/comments', comments: @message.comments
|
data/jbuilder.gemspec
CHANGED
data/lib/jbuilder.rb
CHANGED
@@ -41,7 +41,7 @@ class Jbuilder < JbuilderProxy
|
|
41
41
|
def format(key)
|
42
42
|
@cache[key] ||= @format.inject(key.to_s) do |result, args|
|
43
43
|
func, args = args
|
44
|
-
if
|
44
|
+
if ::Proc === func
|
45
45
|
func.call result, *args
|
46
46
|
else
|
47
47
|
result.send func, *args
|
@@ -64,15 +64,6 @@ class Jbuilder < JbuilderProxy
|
|
64
64
|
options = args.extract_options!
|
65
65
|
@key_formatter = options.fetch(:key_formatter, @@key_formatter.clone)
|
66
66
|
@ignore_nil = options.fetch(:ignore_nil, @@ignore_nil)
|
67
|
-
|
68
|
-
# old-style initialization compatibility
|
69
|
-
if args.any?
|
70
|
-
@key_formatter = args.shift
|
71
|
-
@ignore_nil = args.shift if args.any?
|
72
|
-
::ActiveSupport::Deprecation.warn 'Initialization with positioned ' +
|
73
|
-
'arguments is deprecated. Use hash syntax instead.'
|
74
|
-
end
|
75
|
-
|
76
67
|
yield self if block
|
77
68
|
end
|
78
69
|
|
@@ -104,7 +95,7 @@ class Jbuilder < JbuilderProxy
|
|
104
95
|
elsif value.respond_to?(:map)
|
105
96
|
# json.comments @post.comments, :content, :created_at
|
106
97
|
# { "comments": [ { "content": "hello", "created_at": "..." }, { "content": "world", "created_at": "..." } ] }
|
107
|
-
|
98
|
+
_scope{ array! value, *args }
|
108
99
|
else
|
109
100
|
# json.author @post.creator, :name, :email_address
|
110
101
|
# { "author": { "name": "David", "email_address": "david@loudthinking.com" } }
|
@@ -196,7 +187,7 @@ class Jbuilder < JbuilderProxy
|
|
196
187
|
# json.content comment.formatted_content
|
197
188
|
# end
|
198
189
|
def child!
|
199
|
-
@attributes = [] unless @attributes
|
190
|
+
@attributes = [] unless ::Array === @attributes
|
200
191
|
@attributes << _scope { yield self }
|
201
192
|
end
|
202
193
|
|
@@ -231,8 +222,10 @@ class Jbuilder < JbuilderProxy
|
|
231
222
|
#
|
232
223
|
# [1,2,3]
|
233
224
|
def array!(collection, *attributes, &block)
|
234
|
-
@attributes = if block
|
235
|
-
|
225
|
+
@attributes = if block && block.arity == 2
|
226
|
+
_two_arguments_map_collection(collection, &block)
|
227
|
+
elsif block
|
228
|
+
_map_collection(collection, &block)
|
236
229
|
elsif attributes.any?
|
237
230
|
_map_collection(collection) { |element| extract! element, *attributes }
|
238
231
|
else
|
@@ -258,13 +251,21 @@ class Jbuilder < JbuilderProxy
|
|
258
251
|
#
|
259
252
|
# json.(@person, :name, :age)
|
260
253
|
def extract!(object, *attributes)
|
261
|
-
if
|
254
|
+
if ::Hash === object
|
262
255
|
attributes.each { |attribute| _set_value attribute, object.fetch(attribute) }
|
263
256
|
else
|
264
257
|
attributes.each { |attribute| _set_value attribute, object.send(attribute) }
|
265
258
|
end
|
266
259
|
end
|
267
260
|
|
261
|
+
def call(object, *attributes, &block)
|
262
|
+
if block
|
263
|
+
array! object, &block
|
264
|
+
else
|
265
|
+
extract! object, *attributes
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
268
269
|
# Returns the nil JSON.
|
269
270
|
def nil!
|
270
271
|
@attributes = nil
|
@@ -272,15 +273,6 @@ class Jbuilder < JbuilderProxy
|
|
272
273
|
|
273
274
|
alias_method :null!, :nil!
|
274
275
|
|
275
|
-
|
276
|
-
def call(object = nil, *attributes)
|
277
|
-
if attributes.empty?
|
278
|
-
array! object, &::Proc.new
|
279
|
-
else
|
280
|
-
extract! object, *attributes
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
276
|
# Returns the attributes of the current builder.
|
285
277
|
def attributes!
|
286
278
|
@attributes
|
@@ -318,13 +310,29 @@ class Jbuilder < JbuilderProxy
|
|
318
310
|
end
|
319
311
|
|
320
312
|
def _merge(hash_or_array)
|
321
|
-
if
|
322
|
-
@attributes = [] unless @attributes
|
313
|
+
if ::Array === hash_or_array
|
314
|
+
@attributes = [] unless ::Array === @attributes
|
323
315
|
@attributes.concat hash_or_array
|
324
316
|
else
|
325
317
|
@attributes.update hash_or_array
|
326
318
|
end
|
327
319
|
end
|
320
|
+
|
321
|
+
def _two_arguments_map_collection(collection, &block)
|
322
|
+
message = "Passing jbuilder object to block is " \
|
323
|
+
"deprecated and will be removed soon."
|
324
|
+
|
325
|
+
if block.respond_to?(:parameters)
|
326
|
+
arguments = block.parameters.map(&:last)
|
327
|
+
actual = "|#{arguments.drop(1) * ', '}|"
|
328
|
+
deprecated = "|#{arguments * ', '}|"
|
329
|
+
message += "\nUse #{actual} instead of #{deprecated} as block arguments"
|
330
|
+
end
|
331
|
+
|
332
|
+
::ActiveSupport::Deprecation.warn message, ::Kernel.caller(5)
|
333
|
+
|
334
|
+
_map_collection(collection){ |element| block[self, element] }
|
335
|
+
end
|
328
336
|
end
|
329
337
|
|
330
338
|
require 'jbuilder/jbuilder_template' if defined?(ActionView::Template)
|
data/test/jbuilder_test.rb
CHANGED
@@ -226,8 +226,10 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
226
226
|
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
227
227
|
|
228
228
|
json = Jbuilder.encode do |json|
|
229
|
-
|
230
|
-
json.
|
229
|
+
::ActiveSupport::Deprecation.silence do
|
230
|
+
json.comments comments do |json, comment|
|
231
|
+
json.content comment.content
|
232
|
+
end
|
231
233
|
end
|
232
234
|
end
|
233
235
|
|
@@ -255,8 +257,10 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
255
257
|
comments = [ Comment.new('hello', 1), Comment.new('world', 2) ]
|
256
258
|
|
257
259
|
json = Jbuilder.encode do |json|
|
258
|
-
|
259
|
-
json.
|
260
|
+
::ActiveSupport::Deprecation.silence do
|
261
|
+
json.call(comments) do |json, comment|
|
262
|
+
json.content comment.content
|
263
|
+
end
|
260
264
|
end
|
261
265
|
end
|
262
266
|
|
@@ -317,10 +321,12 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
317
321
|
test 'directly set an array nested in another array with old api' do
|
318
322
|
data = [ { :department => 'QA', :not_in_json => 'hello', :names => ['John', 'David'] } ]
|
319
323
|
json = Jbuilder.encode do |json|
|
320
|
-
|
321
|
-
json.
|
322
|
-
|
323
|
-
json.
|
324
|
+
::ActiveSupport::Deprecation.silence do
|
325
|
+
json.array! data do |json, object|
|
326
|
+
json.department object[:department]
|
327
|
+
json.names do
|
328
|
+
json.array! object[:names]
|
329
|
+
end
|
324
330
|
end
|
325
331
|
end
|
326
332
|
end
|
@@ -457,14 +463,6 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
457
463
|
assert_equal 50, parsed['relations'][1]['age']
|
458
464
|
end
|
459
465
|
|
460
|
-
test 'initialize with positioned arguments (deprecated)' do
|
461
|
-
::ActiveSupport::Deprecation.silence do
|
462
|
-
jbuilder = Jbuilder.new(1, 2)
|
463
|
-
assert_equal 1, jbuilder.instance_eval('@key_formatter')
|
464
|
-
assert_equal 2, jbuilder.instance_eval('@ignore_nil')
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
466
|
test 'initialize via options hash' do
|
469
467
|
jbuilder = Jbuilder.new(:key_formatter => 1, :ignore_nil => 2)
|
470
468
|
assert_equal 1, jbuilder.instance_eval('@key_formatter')
|
metadata
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.4.0
|
4
|
+
version: 1.4.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- David Heinemeier Hansson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: activesupport
|
16
|
-
type: :runtime
|
17
14
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
15
|
requirements:
|
20
16
|
- - ! '>='
|
21
17
|
- !ruby/object:Gem::Version
|
22
18
|
version: 3.0.0
|
23
|
-
prerelease: false
|
24
19
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
20
|
requirements:
|
27
21
|
- - ! '>='
|
28
22
|
- !ruby/object:Gem::Version
|
29
23
|
version: 3.0.0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: multi_json
|
32
24
|
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
name: activesupport
|
27
|
+
- !ruby/object:Gem::Dependency
|
33
28
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
29
|
requirements:
|
36
30
|
- - ! '>='
|
37
31
|
- !ruby/object:Gem::Version
|
38
32
|
version: 1.2.0
|
39
|
-
prerelease: false
|
40
33
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
34
|
requirements:
|
43
35
|
- - ! '>='
|
44
36
|
- !ruby/object:Gem::Version
|
45
37
|
version: 1.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
name: multi_json
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: rake
|
48
|
-
type: :development
|
49
42
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
43
|
requirements:
|
52
44
|
- - ~>
|
53
45
|
- !ruby/object:Gem::Version
|
54
46
|
version: 10.0.3
|
55
|
-
prerelease: false
|
56
47
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
48
|
requirements:
|
59
49
|
- - ~>
|
60
50
|
- !ruby/object:Gem::Version
|
61
51
|
version: 10.0.3
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
name: rake
|
62
55
|
description:
|
63
56
|
email: david@37signals.com
|
64
57
|
executables: []
|
@@ -88,30 +81,30 @@ files:
|
|
88
81
|
homepage:
|
89
82
|
licenses:
|
90
83
|
- MIT
|
84
|
+
metadata: {}
|
91
85
|
post_install_message:
|
92
86
|
rdoc_options: []
|
93
87
|
require_paths:
|
94
88
|
- lib
|
95
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
90
|
requirements:
|
98
91
|
- - ! '>='
|
99
92
|
- !ruby/object:Gem::Version
|
100
93
|
version: '0'
|
101
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
95
|
requirements:
|
104
96
|
- - ! '>='
|
105
97
|
- !ruby/object:Gem::Version
|
106
98
|
version: '0'
|
107
99
|
requirements: []
|
108
100
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.0.3
|
110
102
|
signing_key:
|
111
|
-
specification_version:
|
103
|
+
specification_version: 4
|
112
104
|
summary: Create JSON structures via a Builder-style DSL
|
113
105
|
test_files:
|
114
106
|
- test/jbuilder_generator_test.rb
|
115
107
|
- test/jbuilder_template_test.rb
|
116
108
|
- test/jbuilder_test.rb
|
117
109
|
- test/scaffold_controller_generator_test.rb
|
110
|
+
has_rdoc:
|