jbuilder 2.6.1 → 2.11.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +108 -0
- data/.gitignore +2 -0
- data/Appraisals +16 -35
- data/CONTRIBUTING.md +4 -6
- data/Gemfile +0 -1
- data/MIT-LICENSE +1 -1
- data/README.md +99 -19
- data/Rakefile +2 -6
- data/gemfiles/rails_5_0.gemfile +3 -6
- data/gemfiles/rails_5_1.gemfile +10 -0
- data/gemfiles/rails_5_2.gemfile +10 -0
- data/gemfiles/rails_6_0.gemfile +10 -0
- data/gemfiles/rails_6_1.gemfile +10 -0
- data/gemfiles/rails_head.gemfile +10 -0
- data/jbuilder.gemspec +20 -6
- data/lib/generators/rails/jbuilder_generator.rb +12 -2
- data/lib/generators/rails/scaffold_controller_generator.rb +7 -1
- data/lib/generators/rails/templates/api_controller.rb +4 -4
- data/lib/generators/rails/templates/controller.rb +15 -19
- data/lib/generators/rails/templates/index.json.jbuilder +1 -1
- data/lib/generators/rails/templates/partial.json.jbuilder +16 -2
- data/lib/generators/rails/templates/show.json.jbuilder +1 -1
- data/lib/jbuilder/collection_renderer.rb +109 -0
- data/lib/jbuilder/errors.rb +7 -0
- data/lib/jbuilder/jbuilder_template.rb +65 -16
- data/lib/jbuilder/railtie.rb +1 -1
- data/lib/jbuilder.rb +70 -28
- data/test/jbuilder_dependency_tracker_test.rb +2 -2
- data/test/jbuilder_generator_test.rb +25 -5
- data/test/jbuilder_template_test.rb +280 -323
- data/test/jbuilder_test.rb +256 -4
- data/test/scaffold_api_controller_generator_test.rb +18 -3
- data/test/scaffold_controller_generator_test.rb +41 -8
- data/test/test_helper.rb +30 -8
- metadata +25 -31
- data/.travis.yml +0 -44
- data/CHANGELOG.md +0 -234
- data/gemfiles/rails_3_0.gemfile +0 -14
- data/gemfiles/rails_3_1.gemfile +0 -14
- data/gemfiles/rails_3_2.gemfile +0 -14
- data/gemfiles/rails_4_0.gemfile +0 -13
- data/gemfiles/rails_4_1.gemfile +0 -13
- data/gemfiles/rails_4_2.gemfile +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9ce8fbeac8b34ee290535e98a284a1247e2de1b5272c4679c1b89a89ff8149db
|
4
|
+
data.tar.gz: cdaeb1302c4755ca43f037328698afe29fe658f2094c99e2c6f81f0000b9368c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6903b1aa13786fd5501d8e667eb7a913ebd469d24ce183a24cdf949a62788b1e598c2e0678c5ed5e369d4232c7720e284850f735c5be6f4691e4ecf42256d21a
|
7
|
+
data.tar.gz: 2a40e415a25a4d8680ac00ba81b9984188ef35440869a357db4fd7184d3f0b36d0ce10545a0d5253e6d12374b2f1d51f5a96f1ded1370ec7eddecaee469afc61
|
@@ -0,0 +1,108 @@
|
|
1
|
+
name: Ruby test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }})
|
8
|
+
runs-on: ubuntu-20.04
|
9
|
+
continue-on-error: ${{ matrix.experimental }}
|
10
|
+
env:
|
11
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
12
|
+
BUNDLE_JOBS: 4
|
13
|
+
BUNDLE_RETRY: 3
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
ruby:
|
18
|
+
- "2.2"
|
19
|
+
- "2.3"
|
20
|
+
- "2.4"
|
21
|
+
- "2.5"
|
22
|
+
- "2.6"
|
23
|
+
- "2.7"
|
24
|
+
- "3.0"
|
25
|
+
|
26
|
+
gemfile:
|
27
|
+
- "rails_5_0"
|
28
|
+
- "rails_5_1"
|
29
|
+
- "rails_5_2"
|
30
|
+
- "rails_6_0"
|
31
|
+
- "rails_6_1"
|
32
|
+
- "rails_head"
|
33
|
+
|
34
|
+
experimental: [false]
|
35
|
+
exclude:
|
36
|
+
- ruby: 2.7
|
37
|
+
gemfile: rails_5_0
|
38
|
+
- ruby: '3.0'
|
39
|
+
gemfile: rails_5_0
|
40
|
+
- ruby: head
|
41
|
+
gemfile: rails_5_0
|
42
|
+
- ruby: 2.7
|
43
|
+
gemfile: rails_5_1
|
44
|
+
- ruby: '3.0'
|
45
|
+
gemfile: rails_5_1
|
46
|
+
- ruby: head
|
47
|
+
gemfile: rails_5_1
|
48
|
+
- ruby: 2.2
|
49
|
+
gemfile: rails_5_2
|
50
|
+
- ruby: 2.7
|
51
|
+
gemfile: rails_5_2
|
52
|
+
- ruby: '3.0'
|
53
|
+
gemfile: rails_5_2
|
54
|
+
- ruby: head
|
55
|
+
gemfile: rails_5_2
|
56
|
+
- ruby: 2.2
|
57
|
+
gemfile: rails_6_0
|
58
|
+
- ruby: 2.3
|
59
|
+
gemfile: rails_6_0
|
60
|
+
- ruby: 2.4
|
61
|
+
gemfile: rails_6_0
|
62
|
+
- ruby: '3.0'
|
63
|
+
gemfile: rails_6_0
|
64
|
+
- ruby: head
|
65
|
+
gemfile: rails_6_0
|
66
|
+
- ruby: 2.2
|
67
|
+
gemfile: rails_6_1
|
68
|
+
- ruby: 2.3
|
69
|
+
gemfile: rails_6_1
|
70
|
+
- ruby: 2.4
|
71
|
+
gemfile: rails_6_1
|
72
|
+
- ruby: 2.2
|
73
|
+
gemfile: rails_head
|
74
|
+
- ruby: 2.3
|
75
|
+
gemfile: rails_head
|
76
|
+
- ruby: 2.4
|
77
|
+
gemfile: rails_head
|
78
|
+
- ruby: 2.5
|
79
|
+
gemfile: rails_head
|
80
|
+
- ruby: 2.6
|
81
|
+
gemfile: rails_head
|
82
|
+
- ruby: 2.7
|
83
|
+
gemfile: rails_head
|
84
|
+
experimental: false
|
85
|
+
- ruby: '3.0'
|
86
|
+
gemfile: rails_head
|
87
|
+
experimental: false
|
88
|
+
include:
|
89
|
+
- ruby: 2.7
|
90
|
+
gemfile: rails_head
|
91
|
+
experimental: true
|
92
|
+
- ruby: '3.0'
|
93
|
+
gemfile: rails_head
|
94
|
+
experimental: true
|
95
|
+
- ruby: head
|
96
|
+
gemfile: rails_head
|
97
|
+
experimental: true
|
98
|
+
|
99
|
+
steps:
|
100
|
+
- uses: actions/checkout@v2
|
101
|
+
|
102
|
+
- uses: ruby/setup-ruby@v1
|
103
|
+
with:
|
104
|
+
ruby-version: ${{ matrix.ruby }}
|
105
|
+
bundler-cache: true
|
106
|
+
|
107
|
+
- name: Ruby test
|
108
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,44 +1,25 @@
|
|
1
|
-
appraise "rails-
|
2
|
-
gem "
|
3
|
-
gem "railties", "~> 3.0.0"
|
4
|
-
gem "actionpack", "~> 3.0.0"
|
5
|
-
gem "activemodel", "~> 3.0.0"
|
6
|
-
end
|
7
|
-
|
8
|
-
appraise "rails-3-1" do
|
9
|
-
gem "test-unit"
|
10
|
-
gem "railties", "~> 3.1.0"
|
11
|
-
gem "actionpack", "~> 3.1.0"
|
12
|
-
gem "activemodel", "~> 3.1.0"
|
1
|
+
appraise "rails-5-0" do
|
2
|
+
gem "rails", "~> 5.0.0"
|
13
3
|
end
|
14
4
|
|
15
|
-
appraise "rails-
|
16
|
-
gem "
|
17
|
-
gem "railties", "~> 3.2.0"
|
18
|
-
gem "actionpack", "~> 3.2.0"
|
19
|
-
gem "activemodel", "~> 3.2.0"
|
5
|
+
appraise "rails-5-1" do
|
6
|
+
gem "rails", "~> 5.1.0"
|
20
7
|
end
|
21
8
|
|
22
|
-
appraise "rails-
|
23
|
-
gem "
|
24
|
-
gem "actionpack", "~> 4.0.0"
|
25
|
-
gem "activemodel", "~> 4.0.0"
|
9
|
+
appraise "rails-5-2" do
|
10
|
+
gem "rails", "~> 5.2.0"
|
26
11
|
end
|
27
12
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
13
|
+
if RUBY_VERSION >= "2.5.0"
|
14
|
+
appraise "rails-6-0" do
|
15
|
+
gem "rails", "~> 6.0.0"
|
16
|
+
end
|
33
17
|
|
34
|
-
appraise "rails-
|
35
|
-
|
36
|
-
|
37
|
-
gem "activemodel", "~> 4.2.0"
|
38
|
-
end
|
18
|
+
appraise "rails-6-1" do
|
19
|
+
gem "rails", "~> 6.1.0"
|
20
|
+
end
|
39
21
|
|
40
|
-
appraise "rails-
|
41
|
-
|
42
|
-
|
43
|
-
gem "activemodel", "~> 5.0.0"
|
22
|
+
appraise "rails-head" do
|
23
|
+
gem "rails", github: "rails/rails", branch: "main"
|
24
|
+
end
|
44
25
|
end
|
data/CONTRIBUTING.md
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
Contributing to Jbuilder
|
2
2
|
=====================
|
3
3
|
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/rails/jbuilder/workflows/Ruby%20test/badge.svg)][test]
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/jbuilder.svg)][gem]
|
6
6
|
[![Code Climate](https://codeclimate.com/github/rails/jbuilder/badges/gpa.svg)][codeclimate]
|
7
|
-
[![Dependencies Status](https://gemnasium.com/rails/jbuilder.svg)][gemnasium]
|
8
7
|
|
9
|
-
[
|
8
|
+
[test]: https://github.com/rails/jbuilder/actions?query=branch%3Amaster
|
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
|
|
16
14
|
#### Fork the Project
|
17
15
|
|
18
|
-
Fork the [project on
|
16
|
+
Fork the [project on GitHub](https://github.com/rails/jbuilder) and check out your copy.
|
19
17
|
|
20
18
|
```
|
21
19
|
git clone https://github.com/contributor/jbuilder.git
|
@@ -97,7 +95,7 @@ git push origin my-feature-branch -f
|
|
97
95
|
|
98
96
|
#### Check on Your Pull Request
|
99
97
|
|
100
|
-
Go back to your pull request after a few minutes and see whether it passed muster with
|
98
|
+
Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above.
|
101
99
|
|
102
100
|
#### Be Patient
|
103
101
|
|
data/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -67,6 +67,19 @@ end
|
|
67
67
|
# => {"author": { "name": "David" }}
|
68
68
|
```
|
69
69
|
|
70
|
+
|
71
|
+
To merge existing hash or array to current context:
|
72
|
+
|
73
|
+
``` ruby
|
74
|
+
hash = { author: { name: "David" } }
|
75
|
+
json.post do
|
76
|
+
json.title "Merge HOWTO"
|
77
|
+
json.merge! hash
|
78
|
+
end
|
79
|
+
|
80
|
+
# => "post": { "title": "Merge HOWTO", "author": { "name": "David" } }
|
81
|
+
```
|
82
|
+
|
70
83
|
Top level arrays can be handled directly. Useful for index and other collection actions.
|
71
84
|
|
72
85
|
``` ruby
|
@@ -95,6 +108,33 @@ json.array! @people, :id, :name
|
|
95
108
|
# => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ]
|
96
109
|
```
|
97
110
|
|
111
|
+
To make a plain array without keys, construct and pass in a standard Ruby array.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
my_array = %w(David Jamie)
|
115
|
+
|
116
|
+
json.people my_array
|
117
|
+
|
118
|
+
# => "people": [ "David", "Jamie" ]
|
119
|
+
```
|
120
|
+
|
121
|
+
You don't always have or need a collection when building an array.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
json.people do
|
125
|
+
json.child! do
|
126
|
+
json.id 1
|
127
|
+
json.name 'David'
|
128
|
+
end
|
129
|
+
json.child! do
|
130
|
+
json.id 2
|
131
|
+
json.name 'Jamie'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# => { "people": [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] }
|
136
|
+
```
|
137
|
+
|
98
138
|
Jbuilder objects can be directly nested inside each other. Useful for composing objects.
|
99
139
|
|
100
140
|
``` ruby
|
@@ -124,7 +164,7 @@ company.to_builder.target!
|
|
124
164
|
```
|
125
165
|
|
126
166
|
You can either use Jbuilder stand-alone or directly as an ActionView template
|
127
|
-
language. When required in Rails, you can create views
|
167
|
+
language. When required in Rails, you can create views à la show.json.jbuilder
|
128
168
|
(the json is already yielded):
|
129
169
|
|
130
170
|
``` ruby
|
@@ -143,7 +183,6 @@ if current_user.admin?
|
|
143
183
|
end
|
144
184
|
```
|
145
185
|
|
146
|
-
|
147
186
|
You can use partials as well. The following will render the file
|
148
187
|
`views/comments/_comments.json.jbuilder`, and set a local variable
|
149
188
|
`comments` with all this message's comments, which you can use inside
|
@@ -159,18 +198,37 @@ It's also possible to render collections of partials:
|
|
159
198
|
json.array! @posts, partial: 'posts/post', as: :post
|
160
199
|
|
161
200
|
# or
|
162
|
-
|
163
201
|
json.partial! 'posts/post', collection: @posts, as: :post
|
164
202
|
|
165
203
|
# or
|
166
|
-
|
167
204
|
json.partial! partial: 'posts/post', collection: @posts, as: :post
|
168
205
|
|
169
206
|
# or
|
170
|
-
|
171
207
|
json.comments @post.comments, partial: 'comments/comment', as: :comment
|
172
208
|
```
|
173
209
|
|
210
|
+
The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the
|
211
|
+
partial. If the value is a collection either implicitly or explicitly by using the `collection:` option, then each
|
212
|
+
value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object,
|
213
|
+
then the object is passed to the partial as the variable `some_symbol`.
|
214
|
+
|
215
|
+
Be sure not to confuse the `as:` option to mean nesting of the partial. For example:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
# Use the default `views/comments/_comment.json.jbuilder`, putting @comment as the comment local variable.
|
219
|
+
# Note, `comment` attributes are "inlined".
|
220
|
+
json.partial! @comment, as: :comment
|
221
|
+
```
|
222
|
+
|
223
|
+
is quite different from:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
# comment attributes are nested under a "comment" property
|
227
|
+
json.comment do
|
228
|
+
json.partial! "/comments/comment.json.jbuilder", comment: @comment
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
174
232
|
You can pass any objects into partial templates with or without `:locals` option.
|
175
233
|
|
176
234
|
```ruby
|
@@ -205,6 +263,8 @@ json.bar "bar"
|
|
205
263
|
# => { "bar": "bar" }
|
206
264
|
```
|
207
265
|
|
266
|
+
## Caching
|
267
|
+
|
208
268
|
Fragment caching is supported, it uses `Rails.cache` and works like caching in
|
209
269
|
HTML templates:
|
210
270
|
|
@@ -222,9 +282,25 @@ json.cache_if! !admin?, ['v1', @person], expires_in: 10.minutes do
|
|
222
282
|
end
|
223
283
|
```
|
224
284
|
|
225
|
-
|
226
|
-
|
227
|
-
|
285
|
+
Aside from that, the `:cached` options on collection rendering is available on Rails >= 6.0. This will cache the
|
286
|
+
rendered results effectively using the multi fetch feature.
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
json.array! @posts, partial: "posts/post", as: :post, cached: true
|
290
|
+
|
291
|
+
# or:
|
292
|
+
json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true
|
293
|
+
```
|
294
|
+
|
295
|
+
If your collection cache depends on multiple sources (try to avoid this to keep things simple), you can name all these dependencies as part of a block that returns an array:
|
296
|
+
|
297
|
+
```ruby
|
298
|
+
json.array! @posts, partial: "posts/post", as: :post, cached: -> post { [post, current_user] }
|
299
|
+
```
|
300
|
+
|
301
|
+
This will include both records as part of the cache key and updating either of them will expire the cache.
|
302
|
+
|
303
|
+
## Formatting Keys
|
228
304
|
|
229
305
|
Keys can be auto formatted using `key_format!`, this can be used to convert
|
230
306
|
keynames from the standard ruby_format to camelCase:
|
@@ -243,20 +319,24 @@ environment.rb for example):
|
|
243
319
|
Jbuilder.key_format camelize: :lower
|
244
320
|
```
|
245
321
|
|
246
|
-
|
247
|
-
|
322
|
+
By default, key format is not applied to keys of hashes that are
|
323
|
+
passed to methods like `set!`, `array!` or `merge!`. You can opt into
|
324
|
+
deeply transforming these as well:
|
248
325
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
326
|
+
``` ruby
|
327
|
+
json.key_format! camelize: :lower
|
328
|
+
json.deep_format_keys!
|
329
|
+
json.settings([{some_value: "abc"}])
|
330
|
+
|
331
|
+
# => { "settings": [{ "someValue": "abc" }]}
|
332
|
+
```
|
333
|
+
|
334
|
+
You can set this globally with the class method `deep_format_keys` (from inside your
|
335
|
+
environment.rb for example):
|
255
336
|
|
256
337
|
``` ruby
|
257
|
-
|
258
|
-
|
259
|
-
```
|
338
|
+
Jbuilder.deep_format_keys true
|
339
|
+
```
|
260
340
|
|
261
341
|
## Contributing to Jbuilder
|
262
342
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require "bundler/setup"
|
|
2
2
|
require "bundler/gem_tasks"
|
3
3
|
require "rake/testtask"
|
4
4
|
|
5
|
-
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["
|
5
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"]
|
6
6
|
require "appraisal/task"
|
7
7
|
Appraisal::Task.new
|
8
8
|
task default: :appraisal
|
@@ -12,11 +12,7 @@ else
|
|
12
12
|
|
13
13
|
test.libs << "test"
|
14
14
|
|
15
|
-
|
16
|
-
test.test_files = %w[test/jbuilder_template_test.rb test/jbuilder_test.rb]
|
17
|
-
else
|
18
|
-
test.test_files = FileList["test/*_test.rb"]
|
19
|
-
end
|
15
|
+
test.test_files = FileList["test/*_test.rb"]
|
20
16
|
end
|
21
17
|
|
22
18
|
task default: :test
|
data/gemfiles/rails_5_0.gemfile
CHANGED
@@ -3,11 +3,8 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "rake"
|
6
|
-
gem "mocha", :
|
6
|
+
gem "mocha", require: false
|
7
7
|
gem "appraisal"
|
8
|
-
gem "
|
9
|
-
gem "railties", "~> 5.0.0"
|
10
|
-
gem "actionpack", "~> 5.0.0"
|
11
|
-
gem "activemodel", "~> 5.0.0"
|
8
|
+
gem "rails", "~> 5.0.0"
|
12
9
|
|
13
|
-
gemspec :
|
10
|
+
gemspec path: "../"
|
data/jbuilder.gemspec
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jbuilder'
|
3
|
-
s.version = '2.
|
4
|
-
s.authors =
|
5
|
-
s.email =
|
3
|
+
s.version = '2.11.5'
|
4
|
+
s.authors = 'David Heinemeier Hansson'
|
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', '>=
|
13
|
-
s.add_dependency '
|
12
|
+
s.add_dependency 'activesupport', '>= 5.0.0'
|
13
|
+
s.add_dependency 'actionview', '>= 5.0.0'
|
14
|
+
|
15
|
+
if RUBY_ENGINE == 'rbx'
|
16
|
+
s.add_development_dependency('racc')
|
17
|
+
s.add_development_dependency('json')
|
18
|
+
s.add_development_dependency('rubysl')
|
19
|
+
end
|
14
20
|
|
15
21
|
s.files = `git ls-files`.split("\n")
|
16
22
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
23
|
+
|
24
|
+
s.metadata = {
|
25
|
+
"bug_tracker_uri" => "https://github.com/rails/jbuilder/issues",
|
26
|
+
"changelog_uri" => "https://github.com/rails/jbuilder/releases/tag/v#{s.version}",
|
27
|
+
"mailing_list_uri" => "https://discuss.rubyonrails.org/c/rubyonrails-talk",
|
28
|
+
"source_code_uri" => "https://github.com/rails/jbuilder/tree/v#{s.version}",
|
29
|
+
"rubygems_mfa_required" => "true",
|
30
|
+
}
|
17
31
|
end
|
@@ -10,6 +10,8 @@ module Rails
|
|
10
10
|
|
11
11
|
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
12
12
|
|
13
|
+
class_option :timestamps, type: :boolean, default: true
|
14
|
+
|
13
15
|
def create_root_folder
|
14
16
|
path = File.join('app/views', controller_file_path)
|
15
17
|
empty_directory path unless File.directory?(path)
|
@@ -33,8 +35,12 @@ module Rails
|
|
33
35
|
[name, :json, :jbuilder] * '.'
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
|
38
|
+
def full_attributes_list
|
39
|
+
if options[:timestamps]
|
40
|
+
attributes_list(attributes_names + %w(created_at updated_at))
|
41
|
+
else
|
42
|
+
attributes_list(attributes_names)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
def attributes_list(attributes = attributes_names)
|
@@ -44,6 +50,10 @@ module Rails
|
|
44
50
|
|
45
51
|
attributes.map { |a| ":#{a}"} * ', '
|
46
52
|
end
|
53
|
+
|
54
|
+
def virtual_attributes
|
55
|
+
attributes.select {|name| name.respond_to?(:virtual?) && name.virtual? }
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
@@ -6,7 +6,13 @@ module Rails
|
|
6
6
|
class ScaffoldControllerGenerator
|
7
7
|
source_paths << File.expand_path('../templates', __FILE__)
|
8
8
|
|
9
|
-
hook_for :jbuilder, default: true
|
9
|
+
hook_for :jbuilder, type: :boolean, default: true
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def permitted_params
|
14
|
+
attributes_names.map { |name| ":#{name}" }.join(', ')
|
15
|
+
end unless private_method_defined? :permitted_params
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<% if namespaced? -%>
|
2
|
-
require_dependency "<%=
|
2
|
+
require_dependency "<%= namespaced_path %>/application_controller"
|
3
3
|
|
4
4
|
<% end -%>
|
5
5
|
<% module_namespacing do -%>
|
6
6
|
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
-
before_action :set_<%= singular_table_name %>, only: [
|
7
|
+
before_action :set_<%= singular_table_name %>, only: %i[ show update destroy ]
|
8
8
|
|
9
9
|
# GET <%= route_url %>
|
10
10
|
# GET <%= route_url %>.json
|
@@ -51,12 +51,12 @@ 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}" %>, {})
|
58
58
|
<%- else -%>
|
59
|
-
params.require(<%= ":#{singular_table_name}" %>).permit(<%=
|
59
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
|
60
60
|
<%- end -%>
|
61
61
|
end
|
62
62
|
end
|