grape_serializer 1.0.0 → 1.0.3

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: 7c824e82b65e7a75c6e49b3030db849b5de1d8f76b8c13ffd27c824cfad28c43
4
- data.tar.gz: 686c045c1d63d3e4f467c89e1d737d4b8ab4b2a7123d101d7739d2576708949b
3
+ metadata.gz: c2ecd6b18adf50c54e6d60b4b3ff921cc33a5af0232905de271b1be34e03e35b
4
+ data.tar.gz: b066c3dc899b6d98ca2bbf55286a0436dd32957a5ece0474280c7f6cce544f1e
5
5
  SHA512:
6
- metadata.gz: 3e3f62693aafcaf7a71c008fe725ce32c3a910441b8e68f3a1d5de2cd0501b191e06ddf83eb32a10e3c7f040240863d0ccffa9ea38d1e0032683791d216c7205
7
- data.tar.gz: b13ef389568173507f30784300e82c0fcae3407ee4dd081d333072952c31eecbe51433ac3b1f11850094a1f270c4dfbbe8ac2a0c06c8575ccbfcb0ccc3826f38
6
+ metadata.gz: 51e5b84a476a6474470c61dcdb19e32c21e5fd7f1da016c5624bf5284ee0fcf6396745cb365adb3a9ea96c0e624206e9356872136e6b360575bafab0bfe76e9d
7
+ data.tar.gz: 97163bc840a35b30051392eb047dec71c5b292191ca8608908899d67865741f4718f606307de465c7585a41083db7c84c56898f32783011f8308c0ea7a95981b
@@ -12,13 +12,16 @@ class GrapeSerializer
12
12
  end
13
13
  end
14
14
 
15
+ attr_reader :options
16
+
15
17
  def initialize(params = {})
16
18
  @params = params
17
19
  end
18
20
 
19
21
  def represent(resource, opts = {})
22
+ @options = opts.merge!(@params)
20
23
  preload_associations(resource) if defined?(::Rails::Engine) && defined?(::ActiveRecord) && (resource.is_a?(ActiveRecord::Base) || resource.is_a?(ActiveRecord::Relation))
21
- self.class.entity_class.represent(resource, opts.merge(@params)).as_json
24
+ self.class.entity_class.represent(resource, @options).as_json
22
25
  end
23
26
 
24
27
  protected
data/lib/list_entity.rb CHANGED
@@ -33,8 +33,8 @@ class ListEntity < ServiceEntity
33
33
  def total_pages
34
34
  if pagination_items.respond_to?(:total_pages)
35
35
  pagination_items.total_pages
36
- else
37
- 0
36
+ elsif pagination_items.is_a?(Array)
37
+ pagination_items.length.zero? ? 0 : 1
38
38
  end
39
39
  end
40
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-11 00:00:00.000000000 Z
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-entity