cached_serializer 0.1.0 → 0.1.2

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: 164738a352a3d55ad7ad7efe859c9b4f5840d54f0e21d1ebe5ecbfccbdf16cb8
4
- data.tar.gz: b0b6bdbe968c74de5cd8ad85d772190fa465f5b5c971706c0eb00d409e90ef26
3
+ metadata.gz: bf526cbee1a252e2821fab724ba9a1edd00aa3c85beeb52846b9cc25dc2648de
4
+ data.tar.gz: 263aad0b673d71ff631f6d0cbe0ae27db278009df9ae8b3835943847d523bd9a
5
5
  SHA512:
6
- metadata.gz: c86836b5aa5f676a4f39564f95565c4c3570fcc8063d7f85d0c22e28f78cf5f4acc3bfcd3f0c0594a38a5de5d78fbc774ce3caccb90130185c04f3b2173e5844
7
- data.tar.gz: 275c53b05c3e82d78cdd4aa716b61c6c0465e480c96c22a3e1ca4b99875d2cb7705a6e78951973af07af5ebf463e55132ec7f7a1f53fcb6bc614fb3b503f15ad
6
+ metadata.gz: '059c0ebf3794f4de80a3a3b6c66a54617e96350002951730fd867f7668ac4a27f17e0a91368c8e34beb80a0afdddf1bda71f3d698bc1a7785e27e9bfb0c3f6b3'
7
+ data.tar.gz: 38f0b76d94df50ce19f56a326c34fe3ad757ac0f80d1f39ebb68bd881622ead577690cc6da32fea21e8f2473551c5ce1924653ce3360adcfb27820bfb6afe9ec
@@ -8,7 +8,7 @@ module CachedSerializer
8
8
  end
9
9
  end
10
10
 
11
- def initialize(attr_name, recompute_ifs = nil, :expires_in = nil, &recompute)
11
+ def initialize(attr_name, recompute_ifs = nil, expires_in = nil, &recompute)
12
12
  self.attr_name = attr_name
13
13
  self.recompute_ifs = [recompute_ifs].flatten.compact
14
14
  self.expires_in = expires_in
@@ -25,7 +25,7 @@ module CachedSerializer
25
25
  should_recompute = recompute_ifs.any? { |recompute_if| recompute_if.call(subject) }
26
26
  cache_key = self.class.cache_key(subject, attr_name)
27
27
  Rails.cache.fetch(cache_key, expires_in: expires_in, force: should_recompute) do
28
- attr_serializer.recompute.call(subject)
28
+ recompute.call(subject)
29
29
  end
30
30
  end
31
31
  end
@@ -14,7 +14,7 @@ module CachedSerializer
14
14
  existing.recompute = attr_serializer.recompute # shadowed attrs override the blocks of previously-declared ones
15
15
  existing.expires_in = attr_serializer.expires_in # shadowed attrs override the expires_in of previously-declared ones
16
16
  else
17
- existing << attr_serializer
17
+ collection << attr_serializer
18
18
  end
19
19
  end
20
20
  end
@@ -6,11 +6,9 @@ module CachedSerializer
6
6
  class Base
7
7
  attr_accessor :subject
8
8
 
9
- @serializers = AttrSerializerCollection.new
10
-
11
9
  class << self
12
10
  def serializers
13
- @serializers
11
+ @serializers ||= AttrSerializerCollection.new
14
12
  end
15
13
 
16
14
  # Example (in a UserSerializer):
@@ -121,7 +119,7 @@ module CachedSerializer
121
119
  private
122
120
 
123
121
  def subject_class
124
- @subject_class ||= self.class.to_s.gsub(/[Ss]erializer\z/, '').constantize
122
+ @subject_class ||= self.to_s.gsub(/[Ss]erializer\z/, '').constantize
125
123
  end
126
124
 
127
125
  def add_column_changed_cache_invalidator_callback(attr_name, dependent_attr_name)
@@ -129,10 +127,10 @@ module CachedSerializer
129
127
  @already_added_callback[attr_name.to_sym] ||= {}
130
128
  return if @already_added_callback[attr_name.to_sym][dependent_attr_name.to_sym]
131
129
 
132
- subject_class.class_eval do
133
- after_commit(on: :save) do
130
+ subject_class.instance_eval do
131
+ after_save do
134
132
  if changes[dependent_attr_name.to_s]
135
- Rails.cache.delete(CachedSerializer::AttrSerializer.cache_key(subject, attr_name))
133
+ Rails.cache.delete(CachedSerializer::AttrSerializer.cache_key(self, attr_name))
136
134
  end
137
135
  end
138
136
  end
@@ -1,3 +1,3 @@
1
1
  module CachedSerializer
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keegan Leitz