jbuilder 2.9.1 → 2.10.0

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: 79b2c794b6341ee3d94c4c2d1ed8236e97357dac75dc9e49618a6a885ab35601
4
- data.tar.gz: 4bb8128da8ec6305ae36c3fa866cf19cd1eb08037128b2c3716002525e97014b
3
+ metadata.gz: a7289a23f21f82bfb3eeccd466ec985e8348a9977ed083be43eb8349551e840c
4
+ data.tar.gz: 20d2ba506a7a474d2a32030d91cef03d4345f2332a0753bca685ce6360b30995
5
5
  SHA512:
6
- metadata.gz: c931310549e6384945735110e6c3a2ce36e566d12d691f33d8a5e68f1dca055eeda1ebe606fb093ec85b4c2481c05ebb7dc639f9209a8e4d324f59dd7b4c8693
7
- data.tar.gz: 277b4c68a0fe426e308f6c5fbc59c8b7453d61291aaf3968e4500532f86e902bbc8ac34970ccd2496935c361584773616a4ff71745b7adbabc752b09ba0da9de
6
+ metadata.gz: fc04dfeb7c16b4547d0f7949b30ec481eb8517da3318550cf6c9f5e8bbc7bdc107c2d8bccc94e0e506741926d14f6798e783ece3640abb6edb323a39f7a691ae
7
+ data.tar.gz: 29a6793c2a3b4318b27b2a0614cc88c2a5e4ca646f39a29cb563d370524bc3c946b9ea8bff114b6a5ae9ea5b4e9d3546e30211f0ada15ad74ff028663933e5d7
@@ -16,7 +16,6 @@ rvm:
16
16
  - rbx-3.107
17
17
 
18
18
  gemfile:
19
- - gemfiles/rails_4_2.gemfile
20
19
  - gemfiles/rails_5_0.gemfile
21
20
  - gemfiles/rails_5_1.gemfile
22
21
  - gemfiles/rails_5_2.gemfile
@@ -24,26 +23,7 @@ gemfile:
24
23
  - gemfiles/rails_head.gemfile
25
24
 
26
25
  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
26
  exclude:
41
- - rvm: 2.4.6
42
- gemfile: gemfiles/rails_4_2.gemfile
43
- - rvm: 2.5.5
44
- gemfile: gemfiles/rails_4_2.gemfile
45
- - rvm: 2.6.2
46
- gemfile: gemfiles/rails_4_2.gemfile
47
27
  - rvm: 2.2.10
48
28
  gemfile: gemfiles/rails_6_0.gemfile
49
29
  - rvm: 2.3.8
data/Appraisals CHANGED
@@ -1,24 +1,18 @@
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"
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
- appraise "rails-5-2" do
15
- gem "rails", "~> 5.2.0"
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.rc1"
15
+ gem "rails", "~> 6.0.0"
22
16
  end
23
17
 
24
18
  appraise "rails-head" do
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ 2.10.0
4
+ ----------
5
+
6
+ * Requires Rails 5+ and Ruby 2.2+
7
+ * Nested hashes are deep-merged
8
+
3
9
  2.9.1
4
10
  -----
5
11
 
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rake"
6
6
  gem "mocha", require: false
7
7
  gem "appraisal"
8
- gem "rails", "~> 6.0.0.rc1"
8
+ gem "rails", "~> 6.0.0"
9
9
 
10
10
  gemspec path: "../"
@@ -1,15 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'jbuilder'
3
- s.version = '2.9.1'
3
+ s.version = '2.10.0'
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'
12
+ s.add_dependency 'activesupport', '>= 5.0.0'
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -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
- # 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}" %>, {})
@@ -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
- # Never trust parameters from the scary internet, only allow the white list through.
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}" %>, {})
@@ -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, &::Proc.new }
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, &::Proc.new)
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
- # If you are using Ruby 1.9+, you can use the call syntax instead of an explicit extract! call:
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, &::Proc.new)
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, &::Proc.new
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.merge(updates)
279
+ current_value.deep_merge(updates)
279
280
  else
280
281
  raise MergeError.build(current_value, updates)
281
282
  end
@@ -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, &::Proc.new) : yield
76
+ def cache_if!(condition, *args, &block)
77
+ condition ? cache!(*args, &block) : yield
78
78
  end
79
79
 
80
80
  def target!
@@ -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 for 1.9' do
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'
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.9.1
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-14 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
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: 4.2.0
26
+ version: 5.0.0
27
27
  description:
28
28
  email: david@basecamp.com
29
29
  executables: []
@@ -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
@@ -80,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
79
  requirements:
81
80
  - - ">="
82
81
  - !ruby/object:Gem::Version
83
- version: 1.9.3
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.0.3
89
+ rubygems_version: 3.0.6
91
90
  signing_key:
92
91
  specification_version: 4
93
92
  summary: Create JSON structures via a Builder-style DSL
@@ -1,10 +0,0 @@
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", "~> 4.2.0"
9
-
10
- gemspec path: "../"