redisize 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redisize/version.rb +1 -1
- data/lib/redisize.rb +17 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b7b65e687f5003dac2ba7e92d42450cea066554ce88bccb49c210ff0a413d41
|
4
|
+
data.tar.gz: 95e775070c058d4f3804d03bb082969146c6e5402aec915d489a11eca262214e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b26a2aa8e95fd8de86db627fb45207af2bbebaaaf5fc468b2b4ed8d2f9675a83f8e4852c8d1adbd1150a03bd4dd00a588d2c67c9b5a3ed30f30ddb7f05544c72
|
7
|
+
data.tar.gz: b2493b59261c6c0cbe9962c6dd7e97b635de114695d77373c56608a723b78d9f2e655d59605c2788b4ca978f0e2161b0177c3db7c3c6673126af95dd5e9f1d19
|
data/lib/redisize/version.rb
CHANGED
data/lib/redisize.rb
CHANGED
@@ -133,7 +133,7 @@ module Redisize
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def key_name_for model_name, attrs, type = "meta"
|
136
|
-
primary_key = model_name.constantize.primary_key
|
136
|
+
primary_key = model_name.constantize.primary_key || attrs.keys.first
|
137
137
|
[type, model_name, primary_key, attrs[primary_key].to_s]
|
138
138
|
end
|
139
139
|
|
@@ -244,7 +244,7 @@ module Redisize
|
|
244
244
|
# self -> model instance
|
245
245
|
def redisize_json scheme, &block
|
246
246
|
primary_key = self.class.primary_key
|
247
|
-
key = ["json", self.class.
|
247
|
+
key = ["json", self.class.polymorphic_base_name, primary_key, self[primary_key].to_s, scheme]
|
248
248
|
|
249
249
|
# binding.pry
|
250
250
|
redisize_cache_fetch(key, expires_in: 1.week) do
|
@@ -259,7 +259,7 @@ module Redisize
|
|
259
259
|
# self -> model instance
|
260
260
|
def deredisize_json scheme, &block
|
261
261
|
primary_key = self.class.primary_key
|
262
|
-
key = ["json", self.class.
|
262
|
+
key = ["json", self.class.polymorphic_base_name, primary_key, self[primary_key], scheme]
|
263
263
|
|
264
264
|
# binding.pry
|
265
265
|
Redisize.enqueue(:deredisize_json_metas, key)
|
@@ -267,13 +267,13 @@ module Redisize
|
|
267
267
|
|
268
268
|
# self -> model instance
|
269
269
|
def deredisize_model
|
270
|
-
Redisize.enqueue(:deredisize_model_metas, self.class.
|
270
|
+
Redisize.enqueue(:deredisize_model_metas, self.class.polymorphic_base_name)
|
271
271
|
end
|
272
272
|
|
273
273
|
# self -> model instance
|
274
274
|
def reredisize_instance
|
275
275
|
attrs = Redisize.as_json_for(self)
|
276
|
-
key = Redisize.key_name_for(self.class.
|
276
|
+
key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
|
277
277
|
|
278
278
|
# binding.pry
|
279
279
|
redisize_cache_write(key, self, expires_in: 1000.years)
|
@@ -283,13 +283,23 @@ module Redisize
|
|
283
283
|
# self -> model instance
|
284
284
|
def deredisize_instance
|
285
285
|
attrs = Redisize.as_json_for(self)
|
286
|
-
key = Redisize.key_name_for(self.class.
|
286
|
+
key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
|
287
287
|
|
288
288
|
# binding.pry
|
289
289
|
Redisize.enqueue(:deredisize_instance_metas, key)
|
290
290
|
end
|
291
291
|
|
292
292
|
module ClassMethods
|
293
|
+
def polymorphic_base_name
|
294
|
+
base_name = base_class.to_s
|
295
|
+
|
296
|
+
if base_name == polymorphic_name
|
297
|
+
polymorphic_name
|
298
|
+
else
|
299
|
+
(base_class.to_s.split("::")[0...-1] + [polymorphic_name]).join("::")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
293
303
|
# self -> model class
|
294
304
|
def redisize_sql &block
|
295
305
|
key = ["sql", self.name, self.primary_key, self.all.to_sql]
|
@@ -308,7 +318,7 @@ module Redisize
|
|
308
318
|
def redisize_model value, options = {}, &block
|
309
319
|
primary_key = options.fetch(:by_key, self.primary_key).to_s
|
310
320
|
key = ["instance", name, primary_key, value]
|
311
|
-
metakey = ["meta", self.class.
|
321
|
+
metakey = ["meta", self.class.polymorphic_base_name, primary_key, value]
|
312
322
|
|
313
323
|
# binding.pry
|
314
324
|
redisize_cache_fetch(key, expires_in: 1.week) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redisize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel «Malo» Skrylev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|