active_model_serializers 0.10.12 → 0.10.13

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: 3c046246492aa51d55bec5b8ce5d2a97d9cd0ff8dba206cdde613f47aca0230e
4
- data.tar.gz: 3621cbc3e965bc80389e08b40483b6de73e4a7c7ba7ac96315e1d6e5ee2995e9
3
+ metadata.gz: 94ecdeeabcad7f33e6b2891f2354edeb1fdabf444d9938014d839b554f0a5ab7
4
+ data.tar.gz: cd43b9ceddf4920feb4efae6c5d0748bbb6e37111328c015cdcca06ba8f9d86d
5
5
  SHA512:
6
- metadata.gz: 6fca5a15965145969a683b4f3466a067812ae6680a6a171e885854b6e8e1a684685cb0b37b6ffd52045c8404a95237ddfdd45628e39c0e33a779512ee5a56f5b
7
- data.tar.gz: c32438302db80117e82bec0964c58177cca8579765e5169d127b423927430ab2cff2c51f8b6858e09ea53044b8cf6205524398d0a2e8560738499e9e80983dfa
6
+ metadata.gz: 93b28755ff8f015277534dfc971cab0ef5bf30745bebb34c90e2f6e17c1cb611ef1100ba9e484ebdd1dc415d2c9d1c7e715984a1052e75daada8f712b1126850
7
+ data.tar.gz: 86d257304d0e58b87e82a8c32f55a7722ffdc568dd394ac93214dfe382bf8ff27c8bed24c11f6a948184a16a67ad5fa7bbaf98f2443b2d11c017ce5463c58947
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## 0.10.x
2
2
 
3
- ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.12...0-10-stable)
3
+ ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.13...0-10-stable)
4
4
 
5
5
  Breaking changes:
6
6
 
@@ -10,6 +10,12 @@ Fixes:
10
10
 
11
11
  Misc:
12
12
 
13
+ ### [v0.10.13 (2022-01013)](https://github.com/rails-api/active_model_serializers/compare/v0.10.12...v0.10.13)
14
+
15
+ Fixes:
16
+
17
+ - [#2399](https://github.com/rails-api/active_model_serializers/pull/2399) Handles edge case where requested current_page > total_pages (@f3z0)
18
+
13
19
  ### [v0.10.12 (2020-12-10)](https://github.com/rails-api/active_model_serializers/compare/v0.10.11...v0.10.12)
14
20
 
15
21
  Fixes:
data/README.md CHANGED
@@ -13,7 +13,6 @@
13
13
  <td>
14
14
  <a href="https://codeclimate.com/github/rails-api/active_model_serializers"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg" alt="Code Quality"></a>
15
15
  <a href="https://codebeat.co/projects/github-com-rails-api-active_model_serializers"><img src="https://codebeat.co/badges/a9ab35fa-8b5a-4680-9d4e-a81f9a55ebcd" alt="codebeat" ></a>
16
- <a href="https://codeclimate.com/github/rails-api/active_model_serializers/coverage"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg" alt="Test Coverage"></a>
17
16
  </td>
18
17
  </tr>
19
18
  <tr>
@@ -48,8 +48,11 @@ module ActiveModel
48
48
  key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
49
49
  # 4. key may be nil for empty collection and no serializer option
50
50
  key &&= key.pluralize
51
- # 5. fail if the key cannot be determined
52
- key || fail(ArgumentError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
51
+ if raise_cannot_infer_root_key_error?
52
+ # 5. fail if the key cannot be determined
53
+ key || fail(CannotInferRootKeyError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
54
+ end
55
+ key
53
56
  end
54
57
  # rubocop:enable Metrics/CyclomaticComplexity
55
58
 
@@ -60,12 +63,18 @@ module ActiveModel
60
63
  object.respond_to?(:size)
61
64
  end
62
65
 
66
+ class CannotInferRootKeyError < StandardError; end
67
+
63
68
  protected
64
69
 
65
70
  attr_reader :serializers, :options
66
71
 
67
72
  private
68
73
 
74
+ def raise_cannot_infer_root_key_error?
75
+ ActiveModelSerializers.config.raise_cannot_infer_root_key_error
76
+ end
77
+
69
78
  def serializers_from_resources
70
79
  serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
71
80
  object.map do |resource|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveModel
4
4
  class Serializer
5
- VERSION = '0.10.12'.freeze
5
+ VERSION = '0.10.13'.freeze
6
6
  end
7
7
  end
@@ -146,6 +146,8 @@ module ActiveModel
146
146
  config.jsonapi_include_toplevel_object = false
147
147
  config.jsonapi_use_foreign_key_on_belongs_to_relationship = false
148
148
  config.include_data_default = true
149
+ # Raise ActiveModel::Serializer::CollectionSerializer::CannotInferRootKeyError when cannot infer root key from collection type
150
+ config.raise_cannot_infer_root_key_error = true
149
151
 
150
152
  # For configuring how serializers are found.
151
153
  # This should be an array of procs.
@@ -55,11 +55,15 @@ module ActiveModelSerializers
55
55
 
56
56
  def prev_page_url
57
57
  return nil if collection.current_page == FIRST_PAGE
58
+ if collection.current_page > collection.total_pages
59
+ return url_for_page(collection.total_pages)
60
+ end
58
61
  url_for_page(collection.current_page - FIRST_PAGE)
59
62
  end
60
63
 
61
64
  def next_page_url
62
- return nil if collection.total_pages == 0 || collection.current_page == collection.total_pages
65
+ return nil if collection.total_pages == 0 ||
66
+ collection.current_page >= collection.total_pages
63
67
  url_for_page(collection.next_page)
64
68
  end
65
69
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveModelSerializers
2
3
  class Model
3
4
  module Caching
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.12
4
+ version: 0.10.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '4.1'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '6.2'
42
+ version: '7.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '4.1'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '6.2'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: railties
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: '4.1'
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '6.2'
62
+ version: '7.1'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: '4.1'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '6.2'
72
+ version: '7.1'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: minitest
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +133,7 @@ dependencies:
133
133
  version: '4.1'
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
- version: '6.2'
136
+ version: '7.1'
137
137
  type: :development
138
138
  prerelease: false
139
139
  version_requirements: !ruby/object:Gem::Requirement
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '4.1'
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
- version: '6.2'
146
+ version: '7.1'
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: kaminari
149
149
  requirement: !ruby/object:Gem::Requirement
@@ -192,20 +192,6 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: simplecov
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0.11'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0.11'
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: timecop
211
197
  requirement: !ruby/object:Gem::Requirement
@@ -227,9 +213,6 @@ dependencies:
227
213
  - - ">="
228
214
  - !ruby/object:Gem::Version
229
215
  version: '0.13'
230
- - - "<"
231
- - !ruby/object:Gem::Version
232
- version: 0.19.1
233
216
  type: :development
234
217
  prerelease: false
235
218
  version_requirements: !ruby/object:Gem::Requirement
@@ -237,9 +220,6 @@ dependencies:
237
220
  - - ">="
238
221
  - !ruby/object:Gem::Version
239
222
  version: '0.13'
240
- - - "<"
241
- - !ruby/object:Gem::Version
242
- version: 0.19.1
243
223
  - !ruby/object:Gem::Dependency
244
224
  name: json_schema
245
225
  requirement: !ruby/object:Gem::Requirement
@@ -261,9 +241,6 @@ dependencies:
261
241
  - - ">="
262
242
  - !ruby/object:Gem::Version
263
243
  version: '10.0'
264
- - - "<"
265
- - !ruby/object:Gem::Version
266
- version: '13.0'
267
244
  type: :development
268
245
  prerelease: false
269
246
  version_requirements: !ruby/object:Gem::Requirement
@@ -271,9 +248,6 @@ dependencies:
271
248
  - - ">="
272
249
  - !ruby/object:Gem::Version
273
250
  version: '10.0'
274
- - - "<"
275
- - !ruby/object:Gem::Version
276
- version: '13.0'
277
251
  description: ActiveModel::Serializers allows you to generate your JSON in an object-oriented
278
252
  and convention-driven manner.
279
253
  email: