redisize 0.1.1 → 0.1.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: f15483f3d01901dd9a9807691e315d3e5d2ac3e95d5a583b2422cd4487ed3ce9
4
- data.tar.gz: e41ebdc226aa538d13582432e8b1aacbbeef32f347392ff6147c14ea2fe6f65c
3
+ metadata.gz: f518b11244f545e6dbbd246a4953ee00e85315a9305200c52bfbc1d09359662c
4
+ data.tar.gz: 00f2823251a2351b81cda954070794ad6473fcc0ff5b234ff156f326b991ffa5
5
5
  SHA512:
6
- metadata.gz: 25d10fe2876bd49114431ae4d655f83abbd7288446b86c3742bca58b1b2786758e030683e96155a037c804f78d02ef368cb9a4b675eb5ea4a374fb7fdecf1180
7
- data.tar.gz: b1dc29c5cbc17830a77a6a86cf671a3a2fde8f0854f2a37cd2b98e5b7fec2d9aa7e588c683c9eb7557b1bf122fb55471de5c0e0ad299a908c094fd4b2dbe2afc
6
+ metadata.gz: f0041a03011688e066bc5725fc3cb78fb8c0b8bd32bd58b32560d3c9869382707932e5f31293691d21862fa82983bf40005ccbbacfc6fafadc12e046a10dde99
7
+ data.tar.gz: 316bcd2d0ea078e320188b630b79f9c85e351643acb026ed4b9c460d5f5eb33715373f9188a2578e8f5d0461bf9a16db977e653e08146a7e1d7c771fd936d592
@@ -1,3 +1,3 @@
1
1
  module Redisize
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/redisize.rb CHANGED
@@ -1,6 +1,22 @@
1
1
  require "redisize/version"
2
2
 
3
3
  module Redisize
4
+ # autoloading is required for the proper module loading inside the sidekiq
5
+ module Adapter
6
+ autoload :Sidekiq, File.join(__dir__, 'redisize/adapter/sidekiq.rb')
7
+ autoload :Resque, File.join(__dir__, 'redisize/adapter/resque.rb')
8
+ autoload :Inline, File.join(__dir__, 'redisize/adapter/inline.rb')
9
+ end
10
+ module Cache
11
+ autoload :Rails, File.join(__dir__, 'redisize/cache/rails.rb')
12
+ end
13
+ module Log
14
+ autoload :Rails, File.join(__dir__, 'redisize/log/rails.rb')
15
+ end
16
+ module ORM
17
+ autoload :ActiveRecord, File.join(__dir__, 'redisize/orm/active_record.rb')
18
+ end
19
+
4
20
  class << self
5
21
  attr_writer :adapter
6
22
 
@@ -117,7 +133,7 @@ module Redisize
117
133
  end
118
134
 
119
135
  def key_name_for model_name, attrs, type = "meta"
120
- primary_key = model_name.constantize.primary_key
136
+ primary_key = model_name.constantize.primary_key || attrs.keys.first
121
137
  [type, model_name, primary_key, attrs[primary_key].to_s]
122
138
  end
123
139
 
@@ -228,7 +244,7 @@ module Redisize
228
244
  # self -> model instance
229
245
  def redisize_json scheme, &block
230
246
  primary_key = self.class.primary_key
231
- key = ["json", self.class.polymorphic_name, primary_key, self[primary_key].to_s, scheme]
247
+ key = ["json", self.class.polymorphic_base_name, primary_key, self[primary_key].to_s, scheme]
232
248
 
233
249
  # binding.pry
234
250
  redisize_cache_fetch(key, expires_in: 1.week) do
@@ -243,7 +259,7 @@ module Redisize
243
259
  # self -> model instance
244
260
  def deredisize_json scheme, &block
245
261
  primary_key = self.class.primary_key
246
- key = ["json", self.class.polymorphic_name, primary_key, self[primary_key], scheme]
262
+ key = ["json", self.class.polymorphic_base_name, primary_key, self[primary_key], scheme]
247
263
 
248
264
  # binding.pry
249
265
  Redisize.enqueue(:deredisize_json_metas, key)
@@ -251,13 +267,13 @@ module Redisize
251
267
 
252
268
  # self -> model instance
253
269
  def deredisize_model
254
- Redisize.enqueue(:deredisize_model_metas, self.class.polymorphic_name)
270
+ Redisize.enqueue(:deredisize_model_metas, self.class.polymorphic_base_name)
255
271
  end
256
272
 
257
273
  # self -> model instance
258
274
  def reredisize_instance
259
275
  attrs = Redisize.as_json_for(self)
260
- key = Redisize.key_name_for(self.class.polymorphic_name, attrs, "instance")
276
+ key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
261
277
 
262
278
  # binding.pry
263
279
  redisize_cache_write(key, self, expires_in: 1000.years)
@@ -267,13 +283,17 @@ module Redisize
267
283
  # self -> model instance
268
284
  def deredisize_instance
269
285
  attrs = Redisize.as_json_for(self)
270
- key = Redisize.key_name_for(self.class.polymorphic_name, attrs, "instance")
286
+ key = Redisize.key_name_for(self.class.polymorphic_base_name, attrs, "instance")
271
287
 
272
288
  # binding.pry
273
289
  Redisize.enqueue(:deredisize_instance_metas, key)
274
290
  end
275
291
 
276
292
  module ClassMethods
293
+ def polymorphic_base_name
294
+ (base_class.to_s.split("::")[0...-1] + [polymorphic_name]).join("::")
295
+ end
296
+
277
297
  # self -> model class
278
298
  def redisize_sql &block
279
299
  key = ["sql", self.name, self.primary_key, self.all.to_sql]
@@ -292,7 +312,7 @@ module Redisize
292
312
  def redisize_model value, options = {}, &block
293
313
  primary_key = options.fetch(:by_key, self.primary_key).to_s
294
314
  key = ["instance", name, primary_key, value]
295
- metakey = ["meta", self.class.polymorphic_name, primary_key, value]
315
+ metakey = ["meta", self.class.polymorphic_base_name, primary_key, value]
296
316
 
297
317
  # binding.pry
298
318
  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.1
4
+ version: 0.1.3
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-07-28 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry