grape_serializer 0.1.2 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/grape_serializer.rb +9 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 673094e6fb0ebafb53704d77262aac086b800ae8a9b904208ee6a943dd06442d
4
- data.tar.gz: 71e6e6176efa3475167bbc4614803c4eb91003bf79f5f09c8370ca4398b633e3
3
+ metadata.gz: fa4e4df474e763a22abed0ffb925b97217557d9c26a97a00a211ff46c7edeb49
4
+ data.tar.gz: 142444464287db55fd57b7168def5624be1521ef6062cca7291560dec24f5456
5
5
  SHA512:
6
- metadata.gz: 313e827dd8d5473217d9ce6f10714eb15ff229d0d758c999d6835abfcde439a1b4f0c51e36e079742eedcccc152f41122059f444c8388415a40dbeda582640f2
7
- data.tar.gz: 625e4008b9edcbfa607c404baf36248bfb28159e48586e1bacd36aae4efc42bb845d45fe0e800e2293f24056c11628508fc8e7a09e54e5453bb2cf316c3ab897
6
+ metadata.gz: e99fc0d52af691c3fad9335d544da4557e175c9b20caba4015bdd9161b5e4d7467393b8cbc3ae4b816f779333550b250dc57de131efba1175f80586ab98e6882
7
+ data.tar.gz: 0243e96fc109ee5288b31fe24c5fdbb18a6a15b4d187f29b0fd2a276751179b483f1e21d12c61f724d37af12b633122fb38f8eaebb7215042ccd0ec1bc0667a1
@@ -12,19 +12,26 @@ 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
25
28
 
26
29
  def preload_associations(resource)
27
- ActiveRecord::Associations::Preloader.new.preload(resource, association_array)
30
+ if Rails::VERSION::MAJOR >= 7
31
+ ActiveRecord::Associations::Preloader.new(records: [resource].flatten, associations: association_array).call
32
+ else
33
+ ActiveRecord::Associations::Preloader.new.preload(resource, association_array)
34
+ end
28
35
  end
29
36
 
30
37
  def association_array
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: 0.1.2
4
+ version: 1.0.2
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-05-18 00:00:00.000000000 Z
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape-entity