rails_json_serializer 2.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '090d6170d6135efa9fdc924bb164e456fff8beee34bd6a2378727b264c4eb5fd'
4
- data.tar.gz: 9ec1d082a3d03788007c62bb6aa24be7f184609a3afbc1c6e603831b2b5a205c
3
+ metadata.gz: 661c8d4dea0b016447621acbca1c536e3274e4e70a272e3a67610f380f987833
4
+ data.tar.gz: 642499c67e8e2b7814bc1e550f95f841edfc7895178b3f5483626b2978ea3ba2
5
5
  SHA512:
6
- metadata.gz: 9e0b530149381114f463fb36a023de5cdecc5896721dfa60ebc703349e7c3fe732fe0ec6680a99c9501d9663f530346f2e8c3ace238141f54df49095b77b1afe
7
- data.tar.gz: cbec34221725aafd93682ca7bf00fd96e8513406f8d919492f46ffdad516bdc06c782ba0ea9e6c575dd0fef45c7f40f2d07efd05bdfaadb0fcee22651c9c58dd
6
+ metadata.gz: 0e5964304d7d90cef99365f2df5279ef2edaa3983879f07bcac983ae69ebc94baab7d987be66ef4b578060e147f2c9c294f2144f208c3376d7531d714e4c6b55
7
+ data.tar.gz: ca7f0b5465661b46b985c12797c559e7d795ebebce684331835a7b5a2def49b5cbe88fe72c649f42eb5258cc353698f28007021ee703fb7be9491668ac6fca81
@@ -23,6 +23,20 @@ module ModelSerializer
23
23
  # Inject class methods, will have access to those queries on the class.
24
24
  klass.send(:extend, serializer_klass)
25
25
 
26
+ # Class method to clear the cache of objects without having to instantiate them.
27
+ def self.clear_serializer_cache id_or_ids
28
+ if !id_or_ids.is_a?(Array)
29
+ id_or_ids = [id_or_ids]
30
+ end
31
+ id_or_ids.each do |object_id|
32
+ self::SERIALIZER_QUERY_KEYS_CACHE.each do |query_name|
33
+ cache_key = "#{self.name}_____#{query_name}___#{object_id}"
34
+ puts "(class) CLEARING SERIALIZER CACHE: #{cache_key}" if Rails.env.development?
35
+ Rails.cache.delete(cache_key)
36
+ end
37
+ end
38
+ end
39
+
26
40
  # no need to define it if inheriting class has defined it OR has been manually overridden.
27
41
  # CLASS METHODS
28
42
  klass.send(:define_singleton_method, :serializer) do |opts = {}|
@@ -102,6 +116,11 @@ module ModelSerializer
102
116
 
103
117
 
104
118
  klass.send(:define_method, :as_json) do |options = {}|
119
+ # We don't need to run this custom `as_json` multiple times, if defined on inherited class.
120
+ if options[:ran_serialization]
121
+ return super(options)
122
+ end
123
+ options[:ran_serialization] = true
105
124
  # Not caching records that don't have IDs.
106
125
  if !Serializer.configuration.disable_model_caching && self.id && options[:cache_key].present? && !(options.key?(:cache_for) && options[:cache_for].nil?)
107
126
  cache_key = "#{self.class.name}_____#{options[:cache_key]}___#{self.id}"
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_json_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-04-22 00:00:00.000000000 Z
@@ -14,30 +14,30 @@ dependencies:
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
19
+ version: '5.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: '5.1'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '5.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.1'
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,8 +108,8 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.4'
111
- description:
112
- email:
111
+ description:
112
+ email:
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
@@ -121,7 +121,7 @@ homepage: https://github.com/danabr75/rails_json_serializer
121
121
  licenses:
122
122
  - LGPL-3.0-only
123
123
  metadata: {}
124
- post_install_message:
124
+ post_install_message:
125
125
  rdoc_options: []
126
126
  require_paths:
127
127
  - lib
@@ -136,8 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubygems_version: 3.0.8
140
- signing_key:
139
+ rubygems_version: 3.1.6
140
+ signing_key:
141
141
  specification_version: 4
142
142
  summary: An ActiveRecord JSON Serializer with supported caching and eager-loading
143
143
  test_files: []