jbuilder 2.8.0 → 2.11.2

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
  SHA256:
3
- metadata.gz: 7c134282537dc64d7253ed11314a8ee31402b4fe994626a955b57f308d8bc082
4
- data.tar.gz: eebcdba24d5b41aaf87009296fbb63dd4628677b09955ed7c385e048ad3034a2
3
+ metadata.gz: '039b14d174dd7bfb3a5e00d5a315aee89f1efd46a570244191ab985bb44fc328'
4
+ data.tar.gz: 4eda58d10150903687b7940b858fa02c6f0a2cbca8858cd2ae9866c5be5a4b62
5
5
  SHA512:
6
- metadata.gz: 563cfe1ba9e191ed286ca80f77d7ea41737bb402cd257859ec5ffbf3ee77b7a7b041c3cb433d035f10a68a04df2e186140942a98b78b32d7b6d6e64a6514ff44
7
- data.tar.gz: 8c7e23e0e0aa6abdc56f5a14d4b3ea4c7aa4abdc515d3d8fc8e10385c97733e4f5174a861ffc8fda3913623f90dbb878e7547eec917ebb5d9589d46d9d04c3ba
6
+ metadata.gz: 1d20f2794455635cbb3272bd4b6e8f91781e2c55aa40c7228d5347b4b6ad049cd3cc22ebc9ef708b8bbe4a05811774de07770b175035342123458a4637b9240f
7
+ data.tar.gz: 383aca1c7489eda135339e4538fa8a9dec80900c7c8bab786729a7c323d63f3a75657889ee6dad6bf91b769ced3eb507e41ef7daa15faa8bb3c5d0261c0c0394
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  tmp
2
+ gemfiles/.bundle
2
3
  gemfiles/*.lock
3
4
  Gemfile.lock
4
5
  .ruby-version
5
6
  pkg
7
+ *.gem
data/.travis.yml CHANGED
@@ -1,56 +1,52 @@
1
1
  language: ruby
2
2
 
3
- sudo: false
4
3
  cache: bundler
5
4
 
6
5
  before_install:
7
- - gem update --system
8
- - gem install bundler
6
+ - "gem install bundler -v '<2'"
9
7
 
10
8
  rvm:
11
- - 1.9
12
- - 2.0
13
- - 2.1
14
9
  - 2.2.10
15
- - 2.3.7
16
- - 2.4.4
17
- - 2.5.1
10
+ - 2.3.8
11
+ - 2.4.10
12
+ - 2.5.8
13
+ - 2.6.6
14
+ - 2.7.1
18
15
  - ruby-head
19
- - jruby-19mode
20
- - rbx
21
16
 
22
17
  gemfile:
23
- - gemfiles/rails_4_2.gemfile
24
18
  - gemfiles/rails_5_0.gemfile
25
19
  - gemfiles/rails_5_1.gemfile
20
+ - gemfiles/rails_5_2.gemfile
21
+ - gemfiles/rails_6_0.gemfile
22
+ - gemfiles/rails_head.gemfile
26
23
 
27
24
  matrix:
28
- allow_failures:
29
- - rvm: jruby-19mode
30
- - rvm: rbx
31
- - rvm: ruby-head
32
- fast_finish: true
33
25
  exclude:
34
- - rvm: 1.9
35
- gemfile: gemfiles/rails_5_0.gemfile
36
- - rvm: 1.9
37
- gemfile: gemfiles/rails_5_1.gemfile
38
- - rvm: 2.0
39
- gemfile: gemfiles/rails_5_0.gemfile
40
- - rvm: 2.0
41
- gemfile: gemfiles/rails_5_1.gemfile
42
- - rvm: 2.1
26
+ - rvm: 2.7.1
43
27
  gemfile: gemfiles/rails_5_0.gemfile
44
- - rvm: 2.1
45
- gemfile: gemfiles/rails_5_1.gemfile
46
- - rvm: jruby-19mode
47
- gemfile: gemfiles/rails_5_0.gemfile
48
- - rvm: jruby-19mode
49
- gemfile: gemfiles/rails_5_1.gemfile
50
- - rvm: rbx
51
- gemfile: gemfiles/rails_5_0.gemfile
52
- - rvm: rbx
28
+ - rvm: 2.7.1
53
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
34
+ - rvm: 2.2.10
35
+ gemfile: gemfiles/rails_6_0.gemfile
36
+ - rvm: 2.3.8
37
+ gemfile: gemfiles/rails_6_0.gemfile
38
+ - rvm: 2.4.10
39
+ gemfile: gemfiles/rails_6_0.gemfile
40
+ - rvm: 2.2.10
41
+ gemfile: gemfiles/rails_head.gemfile
42
+ - rvm: 2.3.8
43
+ gemfile: gemfiles/rails_head.gemfile
44
+ - rvm: 2.4.10
45
+ gemfile: gemfiles/rails_head.gemfile
46
+ allow_failures:
47
+ - rvm: ruby-head
48
+ - gemfile: gemfiles/rails_head.gemfile
49
+ fast_finish: true
54
50
 
55
51
  notifications:
56
52
  email: false
data/Appraisals CHANGED
@@ -1,13 +1,21 @@
1
- appraise "rails-4-2" do
2
- gem "rails", "~> 4.2.0"
1
+ appraise "rails-5-0" do
2
+ gem "rails", "~> 5.0.0"
3
3
  end
4
4
 
5
- if RUBY_VERSION >= "2.2.2"
6
- appraise "rails-5-0" do
7
- gem "rails", ">= 5.0.0", "< 5.1"
5
+ appraise "rails-5-1" do
6
+ gem "rails", "~> 5.1.0"
7
+ end
8
+
9
+ appraise "rails-5-2" do
10
+ gem "rails", "~> 5.2.0"
11
+ end
12
+
13
+ if RUBY_VERSION >= "2.5.0"
14
+ appraise "rails-6-0" do
15
+ gem "rails", "~> 6.0.0"
8
16
  end
9
17
 
10
- appraise "rails-5-1" do
11
- gem "rails", ">= 5.1.0", "< 5.2"
18
+ appraise "rails-head" do
19
+ gem "rails", github: "rails/rails"
12
20
  end
13
21
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changelog
2
2
 
3
+ 2.11.2
4
+ ------
5
+
6
+ * [Improve key formatting for nested hashes and disable by default](https://github.com/rails/jbuilder/pull/497)
7
+
8
+ 2.11.1
9
+ ------
10
+
11
+ * Use symbols instead of strings for before_action filters [DHH]
12
+ * Slim down comments in generated scaffold code [DHH]
13
+
14
+ 2.11.0
15
+ ------
16
+
17
+ * [Allow jbuilder instance to be passed to #merge!](https://github.com/rails/jbuilder/pull/485)
18
+ * [Fix for key_format! when using nested hashes](https://github.com/rails/jbuilder/pull/486)
19
+ * [Include rich_text, attachment, and attachments fields in json partial](https://github.com/rails/jbuilder/pull/459)
20
+
21
+ 2.10.2
22
+ ------
23
+
24
+ * Update scaffold generator to use double quotes, 422 form error responds, and modern string-of-arrays syntax [DHH]
25
+
26
+ 2.10.1
27
+ ------
28
+
29
+ * Fix keyword arguments warning on Ruby 2.7
30
+
31
+ 2.10.0
32
+ ------
33
+
34
+ * Requires Rails 5+ and Ruby 2.2+
35
+ * Nested hashes are deep-merged
36
+
37
+ 2.9.1
38
+ -----
39
+
40
+ * [Respect JSON encoding customizations](https://github.com/rails/jbuilder/commit/e2e8623b08078ad6a2323ce8ecaf642b7afe1166)
41
+
42
+ 2.9.0
43
+ -----
44
+
45
+ * [Fix passing object with partial without locals](https://github.com/rails/jbuilder/pull/435)
46
+ * [Fix deprecation warning in Rails 6.0](https://github.com/rails/jbuilder/pull/453)
47
+ * [Use quotes consistently in generated templates](https://github.com/rails/jbuilder/pull/455)
48
+ * [Allow omitting timestamps from generated partials](https://github.com/rails/jbuilder/pull/448)
49
+ * [Respect changing scaffold generator](https://github.com/rails/jbuilder/pull/458)
50
+ * [Use a symbolic default format for Rails 6.0 forward compatibility](https://github.com/rails/jbuilder/commit/3895a7243f3db292b0bf15513fc05494e6e50576)
51
+ * [Drop MultiJSON in favor of Ruby standard library JSON](https://github.com/rails/jbuilder/commit/b952ae096eb1828b0fcfde06e6ba62311494ec49)
52
+
3
53
  2.8.0
4
54
  -----
5
55
 
data/CONTRIBUTING.md CHANGED
@@ -4,18 +4,16 @@ Contributing to Jbuilder
4
4
  [![Build Status](https://api.travis-ci.org/rails/jbuilder.svg?branch=master)][travis]
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
  [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
 
16
14
  #### Fork the Project
17
15
 
18
- Fork the [project on Github](https://github.com/rails/jbuilder) and check out your copy.
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
data/Gemfile CHANGED
@@ -5,4 +5,3 @@ gemspec
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
data/README.md CHANGED
@@ -156,7 +156,6 @@ if current_user.admin?
156
156
  end
157
157
  ```
158
158
 
159
-
160
159
  You can use partials as well. The following will render the file
161
160
  `views/comments/_comments.json.jbuilder`, and set a local variable
162
161
  `comments` with all this message's comments, which you can use inside
@@ -184,6 +183,25 @@ json.partial! partial: 'posts/post', collection: @posts, as: :post
184
183
  json.comments @post.comments, partial: 'comments/comment', as: :comment
185
184
  ```
186
185
 
186
+ The `as: :some_symbol` is used with partials. It will take care of mapping the passed in object to a variable for the partial. If the value is a collection (either implicitly or explicitly by using the `collection:` option, then each value of the collection is passed to the partial as the variable `some_symbol`. If the value is a singular object, then the object is passed to the partial as the variable `some_symbol`.
187
+
188
+ Be sure not to confuse the `as:` option to mean nesting of the partial. For example:
189
+
190
+ ```ruby
191
+ # Use the default `views/comments/_comment.json.jbuilder`, putting @comment as the comment local variable.
192
+ # Note, `comment` attributes are "inlined".
193
+ json.partial! @comment, as: :comment
194
+ ```
195
+
196
+ is quite different than:
197
+
198
+ ```ruby
199
+ # comment attributes are nested under a "comment" property
200
+ json.comment do
201
+ json.partial! "/comments/comment.json.jbuilder", comment: @comment
202
+ end
203
+ ```
204
+
187
205
  You can pass any objects into partial templates with or without `:locals` option.
188
206
 
189
207
  ```ruby
@@ -256,20 +274,24 @@ environment.rb for example):
256
274
  Jbuilder.key_format camelize: :lower
257
275
  ```
258
276
 
259
- Faster JSON backends
260
- --------------------
277
+ By default, key format is not applied to keys of hashes that are
278
+ passed to methods like `set!`, `array!` or `merge!`. You can opt into
279
+ deeply transforming these as well:
261
280
 
262
- Jbuilder uses MultiJson, which by default will use the JSON gem. That gem is
263
- currently tangled with ActiveSupport's all-Ruby `#to_json` implementation,
264
- which is slow (fixed in Rails >= 4.1). For faster Jbuilder rendering, you can
265
- specify something like the Yajl JSON generator instead. You'll need to include
266
- the `yajl-ruby` gem in your Gemfile and then set the following configuration
267
- for MultiJson:
281
+ ``` ruby
282
+ json.key_format! camelize: :lower
283
+ json.deep_format_keys!
284
+ json.settings([{some_value: "abc"}])
285
+
286
+ # => { "settings": [{ "someValue": "abc" }]}
287
+ ```
288
+
289
+ You can set this globally with the class method `deep_format_keys` (from inside your
290
+ environment.rb for example):
268
291
 
269
292
  ``` ruby
270
- require 'multi_json'
271
- MultiJson.use :yajl
272
- ```
293
+ Jbuilder.deep_format_keys true
294
+ ```
273
295
 
274
296
  ## Contributing to Jbuilder
275
297
 
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
9
- gem "rails", ">= 5.0.0", "< 5.1"
8
+ gem "rails", "~> 5.0.0"
10
9
 
11
10
  gemspec path: "../"
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
9
- gem "rails", ">= 5.1.0", "< 5.2"
8
+ gem "rails", "~> 5.1.0"
10
9
 
11
10
  gemspec path: "../"
@@ -5,7 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "pry"
9
- gem "rails", "~> 4.2.0"
8
+ gem "rails", "~> 5.2.0"
10
9
 
11
10
  gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", "~> 6.0.0"
9
+
10
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "mocha", require: false
7
+ gem "appraisal"
8
+ gem "rails", github: "rails/rails"
9
+
10
+ gemspec path: "../"
data/jbuilder.gemspec CHANGED
@@ -1,16 +1,21 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.8.0'
3
+ s.version = '2.11.2'
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 = '>= 1.9.3'
10
+ s.required_ruby_version = '>= 2.2.2'
11
11
 
12
- s.add_dependency 'activesupport', '>= 4.2.0'
13
- s.add_dependency 'multi_json', '>= 1.2'
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
14
19
 
15
20
  s.files = `git ls-files`.split("\n")
16
21
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -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 attributes_list_with_timestamps
37
- attributes_list(attributes_names + %w(created_at updated_at))
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
@@ -7,6 +7,12 @@ module Rails
7
7
  source_paths << File.expand_path('../templates', __FILE__)
8
8
 
9
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 "<%= namespaced_file_path %>/application_controller"
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: [:show, :update, :destroy]
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
- # Never trust parameters from the scary internet, only allow the white list through.
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(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
59
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
60
60
  <%- end -%>
61
61
  end
62
62
  end