rails_json_serializer 1.1.2 → 1.1.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/serializer/concern.rb +35 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9232f08e4be61f2f817b67e734253f02f4970625d32a3a48382170a11ffbc222
4
- data.tar.gz: 58052d52689ed5376c0849f4b478cd319fabebb78d5e95dac9ca21f976fe831e
3
+ metadata.gz: 87d8f10823e559a993218286bc85c0598e077f59e10a23ce0694f3cd41645100
4
+ data.tar.gz: 8b3983a64085b1a7d2e75cfaf10455c93387059cf5e0adb9cd5fec1f19ce2c3f
5
5
  SHA512:
6
- metadata.gz: d8ef6a39473a49fbb46e828ee7428cf237426802aabe9d2277b3d887ab83c49acf7337305a4589851a7c942389101b45618f899ff3afa42ae5803d0f23057290
7
- data.tar.gz: a7a9a49810fde0ec0699d23aaadc24c80f9fd4bc277344646a92e28f4d654f63707c2b77b3ef1f533881f39b69a9882506efbb6e20ee4425e696e24836ee6ef5
6
+ metadata.gz: b0dc86ef87ab82c921885e043c831c07f5e8d47ad3d497316c647522016e2497c07891c7a4b9d52f3b215b091e0c6f7872023365f6480ec0321242d4374a0d17
7
+ data.tar.gz: 2aae2a124dad83d9c04d3088a5539a43f4e47f1b96d3239b9ca755e629a3dad8e9ced58f7c85e2f549c4b94f0d5be2781c751803a8a98b8a83094d75b4013f16
@@ -112,19 +112,32 @@ module Serializer
112
112
  end
113
113
  end
114
114
  end
115
+ if serializer_query_names.any?
116
+ # Inject instance methods
117
+ subclass.send(:include, serializer_klass::SerializerClassAndInstanceMethods)
118
+ # Inject class methods
119
+ subclass.send(:extend, serializer_klass::SerializerClassAndInstanceMethods)
120
+ # Inject class methods that has queries
121
+ if Serializer.configuration.debug
122
+ Rails.logger.info "Injecting queries: #{serializer_klass.public_instance_methods} into class: #{subclass}"
123
+ end
124
+ puts "Injecting queries: #{serializer_klass.public_instance_methods} into class: #{subclass}"
125
+ subclass.send(:extend, serializer_klass)
126
+ # Injecting the Serializer Methods as a namespaced class of the rails class, so we can have
127
+ # access to the list of methods to clear their cache.
128
+ # 'Class Name + Serializer' does not work with inheritence.
129
+ subclass.const_set('SERIALIZER_QUERY_KEYS_CACHE', serializer_query_names)
130
+ # Inject class methods
131
+ subclass.send(:extend, serializer_klass::SerializerClassMethods)
115
132
 
116
- # Inject instance methods
117
- subclass.send(:include, serializer_klass::SerializerClassAndInstanceMethods)
118
- # Inject class methods
119
- subclass.send(:extend, serializer_klass::SerializerClassAndInstanceMethods)
120
- # Inject class methods that has queries
121
- subclass.send(:extend, serializer_klass)
122
- # Injecting the Serializer Methods as a namespaced class of the rails class, so we can have
123
- # access to the list of methods to clear their cache.
124
- # 'Class Name + Serializer' does not work with inheritence.
125
- subclass.const_set('SERIALIZER_QUERY_KEYS_CACHE', serializer_query_names)
126
- # Inject class methods
127
- subclass.send(:extend, serializer_klass::SerializerClassMethods)
133
+ # Issue with inheritting classes caching the serializer data from queries in super classes.
134
+ # Only on the rails server, not the console strangely.
135
+ serializer_query_names.each do |query_name|
136
+ cache_key_prefix = /#{subclass.name}_____#{query_name}___(\d+)/
137
+ puts "Deleting cache here: Rails.cache.delete_matched(#{cache_key_prefix})"
138
+ Rails.cache.delete_matched(cache_key_prefix)
139
+ end
140
+ end
128
141
  else
129
142
  Rails.logger.info "Serializer: #{serializer_klass.name} was not a Module as expected" if Serializer.configuration.debug
130
143
  end
@@ -132,6 +145,16 @@ module Serializer
132
145
  super(subclass)
133
146
  end
134
147
 
148
+ # Class defined clear serializer
149
+ def clear_serializer_cache
150
+ self.get_cumulatively_inherited_serializer_query_list.each do |query_name|
151
+ cache_key_prefix = /#{self.name}_____#{query_name}___(\d+)/
152
+ Rails.logger.info "Serializer: CLEARING CACHE KEY Prefix: #{cache_key_prefix}" if Serializer.configuration.debug
153
+ Rails.cache.delete_matched(cache_key_prefix)
154
+ end
155
+ return true
156
+ end
157
+
135
158
  # Can override the query, using the options. ex: {json_query_override: :tiny_children_serializer_query}
136
159
  def serializer opts = {}
137
160
  query = opts[:json_query_override].present? ? self.send(opts[:json_query_override], opts) : serializer_query(opts)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_json_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - benjamin.dana.software.dev@gmail.com
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2020-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"