jbuilder 2.9.1 → 2.10.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +14 -29
- data/Appraisals +8 -14
- data/CHANGELOG.md +11 -0
- data/CONTRIBUTING.md +0 -2
- data/gemfiles/rails_6_0.gemfile +1 -1
- data/jbuilder.gemspec +9 -3
- data/lib/generators/rails/templates/api_controller.rb +2 -2
- data/lib/generators/rails/templates/controller.rb +2 -2
- data/lib/jbuilder/jbuilder_template.rb +3 -3
- data/lib/jbuilder.rb +11 -10
- data/test/jbuilder_test.rb +20 -1
- data/test/test_helper.rb +1 -1
- metadata +10 -11
- data/gemfiles/rails_4_2.gemfile +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c33305909a9aa4be64b5dd83da1f6a5570654ab50a38042ae404da406f06cca3
|
|
4
|
+
data.tar.gz: 5cc79921463b6cef4f7dbc37dba911e47a6a826824223a4b89a289f6ccf59dea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f2a7e1ed17babb16527afb6e12458ddadcbd5bb2129c110d4e426f573db610d2cc3f9d9d7d06c577c7608c97016c1ec5a60431237362c7d955d0674dcba2de3
|
|
7
|
+
data.tar.gz: cf0820dc816f84fde3a2fa17010ce05e325bba7a830d4a0b7b26dafeafe17a73d2ce6734e7a0f3af54389f304439e58206897efa38bc97c63ba184b545f86ab3
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -3,20 +3,18 @@ language: ruby
|
|
|
3
3
|
cache: bundler
|
|
4
4
|
|
|
5
5
|
before_install:
|
|
6
|
-
- "gem update --system 2.7.9"
|
|
7
6
|
- "gem install bundler -v '<2'"
|
|
8
7
|
|
|
9
8
|
rvm:
|
|
10
9
|
- 2.2.10
|
|
11
10
|
- 2.3.8
|
|
12
|
-
- 2.4.
|
|
13
|
-
- 2.5.
|
|
14
|
-
- 2.6.
|
|
11
|
+
- 2.4.10
|
|
12
|
+
- 2.5.8
|
|
13
|
+
- 2.6.6
|
|
14
|
+
- 2.7.1
|
|
15
15
|
- ruby-head
|
|
16
|
-
- rbx-3.107
|
|
17
16
|
|
|
18
17
|
gemfile:
|
|
19
|
-
- gemfiles/rails_4_2.gemfile
|
|
20
18
|
- gemfiles/rails_5_0.gemfile
|
|
21
19
|
- gemfiles/rails_5_1.gemfile
|
|
22
20
|
- gemfiles/rails_5_2.gemfile
|
|
@@ -24,41 +22,28 @@ gemfile:
|
|
|
24
22
|
- gemfiles/rails_head.gemfile
|
|
25
23
|
|
|
26
24
|
matrix:
|
|
27
|
-
include:
|
|
28
|
-
- rvm: 1.9
|
|
29
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
30
|
-
- rvm: 2.0
|
|
31
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
32
|
-
- rvm: 2.1
|
|
33
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
34
|
-
- rvm: 2.3
|
|
35
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
36
|
-
- rvm: jruby-19mode
|
|
37
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
38
|
-
- rvm: rbx-3.107
|
|
39
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
40
25
|
exclude:
|
|
41
|
-
- rvm: 2.
|
|
42
|
-
gemfile: gemfiles/
|
|
43
|
-
- rvm: 2.
|
|
44
|
-
gemfile: gemfiles/
|
|
45
|
-
- rvm: 2.
|
|
46
|
-
gemfile: gemfiles/
|
|
26
|
+
- rvm: 2.7.1
|
|
27
|
+
gemfile: gemfiles/rails_5_0.gemfile
|
|
28
|
+
- rvm: 2.7.1
|
|
29
|
+
gemfile: gemfiles/rails_5_1.gemfile
|
|
30
|
+
- rvm: 2.2.10
|
|
31
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
|
32
|
+
- rvm: 2.7.1
|
|
33
|
+
gemfile: gemfiles/rails_5_2.gemfile
|
|
47
34
|
- rvm: 2.2.10
|
|
48
35
|
gemfile: gemfiles/rails_6_0.gemfile
|
|
49
36
|
- rvm: 2.3.8
|
|
50
37
|
gemfile: gemfiles/rails_6_0.gemfile
|
|
51
|
-
- rvm: 2.4.
|
|
38
|
+
- rvm: 2.4.10
|
|
52
39
|
gemfile: gemfiles/rails_6_0.gemfile
|
|
53
40
|
- rvm: 2.2.10
|
|
54
41
|
gemfile: gemfiles/rails_head.gemfile
|
|
55
42
|
- rvm: 2.3.8
|
|
56
43
|
gemfile: gemfiles/rails_head.gemfile
|
|
57
|
-
- rvm: 2.4.
|
|
44
|
+
- rvm: 2.4.10
|
|
58
45
|
gemfile: gemfiles/rails_head.gemfile
|
|
59
46
|
allow_failures:
|
|
60
|
-
- rvm: jruby-19mode
|
|
61
|
-
- rvm: rbx-3.107
|
|
62
47
|
- rvm: ruby-head
|
|
63
48
|
- gemfile: gemfiles/rails_head.gemfile
|
|
64
49
|
fast_finish: true
|
data/Appraisals
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
appraise "rails-
|
|
2
|
-
gem "rails", "~>
|
|
1
|
+
appraise "rails-5-0" do
|
|
2
|
+
gem "rails", "~> 5.0.0"
|
|
3
3
|
end
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
appraise "rails-5-1" do
|
|
11
|
-
gem "rails", "~> 5.1.0"
|
|
12
|
-
end
|
|
5
|
+
appraise "rails-5-1" do
|
|
6
|
+
gem "rails", "~> 5.1.0"
|
|
7
|
+
end
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
9
|
+
appraise "rails-5-2" do
|
|
10
|
+
gem "rails", "~> 5.2.0"
|
|
17
11
|
end
|
|
18
12
|
|
|
19
13
|
if RUBY_VERSION >= "2.5.0"
|
|
20
14
|
appraise "rails-6-0" do
|
|
21
|
-
gem "rails", "~> 6.0.0
|
|
15
|
+
gem "rails", "~> 6.0.0"
|
|
22
16
|
end
|
|
23
17
|
|
|
24
18
|
appraise "rails-head" do
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
|
@@ -4,12 +4,10 @@ Contributing to Jbuilder
|
|
|
4
4
|
[][travis]
|
|
5
5
|
[][gem]
|
|
6
6
|
[][codeclimate]
|
|
7
|
-
[][gemnasium]
|
|
8
7
|
|
|
9
8
|
[travis]: https://travis-ci.org/rails/jbuilder
|
|
10
9
|
[gem]: https://rubygems.org/gems/jbuilder
|
|
11
10
|
[codeclimate]: https://codeclimate.com/github/rails/jbuilder
|
|
12
|
-
[gemnasium]: https://gemnasium.com/rails/jbuilder
|
|
13
11
|
|
|
14
12
|
Jbuilder is work of [many contributors](https://github.com/rails/jbuilder/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/jbuilder/pulls), [propose features and discuss issues](https://github.com/rails/jbuilder/issues).
|
|
15
13
|
|
data/gemfiles/rails_6_0.gemfile
CHANGED
data/jbuilder.gemspec
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'jbuilder'
|
|
3
|
-
s.version = '2.
|
|
3
|
+
s.version = '2.10.1'
|
|
4
4
|
s.authors = 'David Heinemeier Hansson'
|
|
5
5
|
s.email = 'david@basecamp.com'
|
|
6
6
|
s.summary = 'Create JSON structures via a Builder-style DSL'
|
|
7
7
|
s.homepage = 'https://github.com/rails/jbuilder'
|
|
8
8
|
s.license = 'MIT'
|
|
9
9
|
|
|
10
|
-
s.required_ruby_version = '>=
|
|
10
|
+
s.required_ruby_version = '>= 2.2.2'
|
|
11
11
|
|
|
12
|
-
s.add_dependency 'activesupport', '>=
|
|
12
|
+
s.add_dependency 'activesupport', '>= 5.0.0'
|
|
13
|
+
|
|
14
|
+
if RUBY_ENGINE == 'rbx'
|
|
15
|
+
s.add_development_dependency('racc')
|
|
16
|
+
s.add_development_dependency('json')
|
|
17
|
+
s.add_development_dependency('rubysl')
|
|
18
|
+
end
|
|
13
19
|
|
|
14
20
|
s.files = `git ls-files`.split("\n")
|
|
15
21
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% if namespaced? -%>
|
|
2
|
-
require_dependency "<%=
|
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
|
3
3
|
|
|
4
4
|
<% end -%>
|
|
5
5
|
<% module_namespacing do -%>
|
|
@@ -51,7 +51,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
|
51
51
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
#
|
|
54
|
+
# Only allow a list of trusted parameters through.
|
|
55
55
|
def <%= "#{singular_table_name}_params" %>
|
|
56
56
|
<%- if attributes_names.empty? -%>
|
|
57
57
|
params.fetch(<%= ":#{singular_table_name}" %>, {})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% if namespaced? -%>
|
|
2
|
-
require_dependency "<%=
|
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
|
3
3
|
|
|
4
4
|
<% end -%>
|
|
5
5
|
<% module_namespacing do -%>
|
|
@@ -72,7 +72,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
|
72
72
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#
|
|
75
|
+
# Only allow a list of trusted parameters through.
|
|
76
76
|
def <%= "#{singular_table_name}_params" %>
|
|
77
77
|
<%- if attributes_names.empty? -%>
|
|
78
78
|
params.fetch(<%= ":#{singular_table_name}" %>, {})
|
|
@@ -73,8 +73,8 @@ class JbuilderTemplate < Jbuilder
|
|
|
73
73
|
# json.cache_if! !admin?, @person, expires_in: 10.minutes do
|
|
74
74
|
# json.extract! @person, :name, :age
|
|
75
75
|
# end
|
|
76
|
-
def cache_if!(condition, *args)
|
|
77
|
-
condition ? cache!(*args,
|
|
76
|
+
def cache_if!(condition, *args, &block)
|
|
77
|
+
condition ? cache!(*args, &block) : yield
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def target!
|
|
@@ -164,7 +164,7 @@ class JbuilderTemplate < Jbuilder
|
|
|
164
164
|
if @context.respond_to?(:cache_fragment_name)
|
|
165
165
|
# Current compatibility, fragment_name_with_digest is private again and cache_fragment_name
|
|
166
166
|
# should be used instead.
|
|
167
|
-
@context.cache_fragment_name(key, options)
|
|
167
|
+
@context.cache_fragment_name(key, **options)
|
|
168
168
|
elsif @context.respond_to?(:fragment_name_with_digest)
|
|
169
169
|
# Backwards compatibility for period of time when fragment_name_with_digest was made public.
|
|
170
170
|
@context.fragment_name_with_digest(key)
|
data/lib/jbuilder.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'jbuilder/key_formatter'
|
|
|
4
4
|
require 'jbuilder/errors'
|
|
5
5
|
require 'json'
|
|
6
6
|
require 'ostruct'
|
|
7
|
+
require 'active_support/core_ext/hash/deep_merge'
|
|
7
8
|
|
|
8
9
|
class Jbuilder
|
|
9
10
|
@@key_formatter = nil
|
|
@@ -26,12 +27,12 @@ class Jbuilder
|
|
|
26
27
|
BLANK = Blank.new
|
|
27
28
|
NON_ENUMERABLES = [ ::Struct, ::OpenStruct ].to_set
|
|
28
29
|
|
|
29
|
-
def set!(key, value = BLANK, *args)
|
|
30
|
+
def set!(key, value = BLANK, *args, &block)
|
|
30
31
|
result = if ::Kernel.block_given?
|
|
31
32
|
if !_blank?(value)
|
|
32
33
|
# json.comments @post.comments { |comment| ... }
|
|
33
34
|
# { "comments": [ { ... }, { ... } ] }
|
|
34
|
-
_scope{ array! value,
|
|
35
|
+
_scope{ array! value, &block }
|
|
35
36
|
else
|
|
36
37
|
# json.comments { ... }
|
|
37
38
|
# { "comments": ... }
|
|
@@ -61,9 +62,9 @@ class Jbuilder
|
|
|
61
62
|
_set_value key, result
|
|
62
63
|
end
|
|
63
64
|
|
|
64
|
-
def method_missing(*args)
|
|
65
|
+
def method_missing(*args, &block)
|
|
65
66
|
if ::Kernel.block_given?
|
|
66
|
-
set!(*args,
|
|
67
|
+
set!(*args, &block)
|
|
67
68
|
else
|
|
68
69
|
set!(*args)
|
|
69
70
|
end
|
|
@@ -163,7 +164,7 @@ class Jbuilder
|
|
|
163
164
|
#
|
|
164
165
|
# [ { "name": David", "age": 32 }, { "name": Jamie", "age": 31 } ]
|
|
165
166
|
#
|
|
166
|
-
#
|
|
167
|
+
# You can use the call syntax instead of an explicit extract! call:
|
|
167
168
|
#
|
|
168
169
|
# json.(@people) { |person| ... }
|
|
169
170
|
#
|
|
@@ -181,11 +182,11 @@ class Jbuilder
|
|
|
181
182
|
# json.array! [1, 2, 3]
|
|
182
183
|
#
|
|
183
184
|
# [1,2,3]
|
|
184
|
-
def array!(collection = [], *attributes)
|
|
185
|
+
def array!(collection = [], *attributes, &block)
|
|
185
186
|
array = if collection.nil?
|
|
186
187
|
[]
|
|
187
188
|
elsif ::Kernel.block_given?
|
|
188
|
-
_map_collection(collection,
|
|
189
|
+
_map_collection(collection, &block)
|
|
189
190
|
elsif attributes.any?
|
|
190
191
|
_map_collection(collection) { |element| extract! element, *attributes }
|
|
191
192
|
else
|
|
@@ -220,9 +221,9 @@ class Jbuilder
|
|
|
220
221
|
end
|
|
221
222
|
end
|
|
222
223
|
|
|
223
|
-
def call(object, *attributes)
|
|
224
|
+
def call(object, *attributes, &block)
|
|
224
225
|
if ::Kernel.block_given?
|
|
225
|
-
array! object,
|
|
226
|
+
array! object, &block
|
|
226
227
|
else
|
|
227
228
|
extract! object, *attributes
|
|
228
229
|
end
|
|
@@ -275,7 +276,7 @@ class Jbuilder
|
|
|
275
276
|
elsif ::Array === current_value && ::Array === updates
|
|
276
277
|
current_value + updates
|
|
277
278
|
elsif ::Hash === current_value && ::Hash === updates
|
|
278
|
-
current_value.
|
|
279
|
+
current_value.deep_merge(updates)
|
|
279
280
|
else
|
|
280
281
|
raise MergeError.build(current_value, updates)
|
|
281
282
|
end
|
data/test/jbuilder_test.rb
CHANGED
|
@@ -99,7 +99,7 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
|
99
99
|
assert_equal 32, result['age']
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
test 'extracting from object using call style
|
|
102
|
+
test 'extracting from object using call style' do
|
|
103
103
|
person = Struct.new(:name, :age).new('David', 32)
|
|
104
104
|
|
|
105
105
|
result = jbuild do |json|
|
|
@@ -159,6 +159,25 @@ class JbuilderTest < ActiveSupport::TestCase
|
|
|
159
159
|
assert_equal 32, result['author']['age']
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
+
test 'nested blocks are additive' do
|
|
163
|
+
result = jbuild do |json|
|
|
164
|
+
json.author do
|
|
165
|
+
json.name do
|
|
166
|
+
json.first 'David'
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
json.author do
|
|
171
|
+
json.name do
|
|
172
|
+
json.last 'Heinemeier Hansson'
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
assert_equal 'David', result['author']['name']['first']
|
|
178
|
+
assert_equal 'Heinemeier Hansson', result['author']['name']['last']
|
|
179
|
+
end
|
|
180
|
+
|
|
162
181
|
test 'support merge! method' do
|
|
163
182
|
result = jbuild do |json|
|
|
164
183
|
json.merge! 'foo' => 'bar'
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jbuilder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.10.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Heinemeier Hansson
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,15 +16,15 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 5.0.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
27
|
-
description:
|
|
26
|
+
version: 5.0.0
|
|
27
|
+
description:
|
|
28
28
|
email: david@basecamp.com
|
|
29
29
|
executables: []
|
|
30
30
|
extensions: []
|
|
@@ -39,7 +39,6 @@ files:
|
|
|
39
39
|
- MIT-LICENSE
|
|
40
40
|
- README.md
|
|
41
41
|
- Rakefile
|
|
42
|
-
- gemfiles/rails_4_2.gemfile
|
|
43
42
|
- gemfiles/rails_5_0.gemfile
|
|
44
43
|
- gemfiles/rails_5_1.gemfile
|
|
45
44
|
- gemfiles/rails_5_2.gemfile
|
|
@@ -72,7 +71,7 @@ homepage: https://github.com/rails/jbuilder
|
|
|
72
71
|
licenses:
|
|
73
72
|
- MIT
|
|
74
73
|
metadata: {}
|
|
75
|
-
post_install_message:
|
|
74
|
+
post_install_message:
|
|
76
75
|
rdoc_options: []
|
|
77
76
|
require_paths:
|
|
78
77
|
- lib
|
|
@@ -80,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
80
79
|
requirements:
|
|
81
80
|
- - ">="
|
|
82
81
|
- !ruby/object:Gem::Version
|
|
83
|
-
version:
|
|
82
|
+
version: 2.2.2
|
|
84
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
84
|
requirements:
|
|
86
85
|
- - ">="
|
|
87
86
|
- !ruby/object:Gem::Version
|
|
88
87
|
version: '0'
|
|
89
88
|
requirements: []
|
|
90
|
-
rubygems_version: 3.
|
|
91
|
-
signing_key:
|
|
89
|
+
rubygems_version: 3.1.2
|
|
90
|
+
signing_key:
|
|
92
91
|
specification_version: 4
|
|
93
92
|
summary: Create JSON structures via a Builder-style DSL
|
|
94
93
|
test_files:
|