cache_depends_on 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: dc9cd539c0b5d27ae04edbc2858505f176fdf130
4
- data.tar.gz: 627fcf125320c3827fbc1be01063b87215e53119
3
+ metadata.gz: 8369280354a8dc49af0ff290e18647e1a7f6cc90
4
+ data.tar.gz: 73ffce26bb06d0eb383575e6414aa1cd3f4704d3
5
5
  SHA512:
6
- metadata.gz: 5f9261d4eebf2386de8a00d59053c099d2f2900c0bb7a6289aadf6bb25447c64f7c000573a60799d98845264a1bf004c021ac626d357721b4f957452d463716a
7
- data.tar.gz: e4eedbe151de73a1d9834f0427e24b009e4bbc75b29a2f169f0014d6a70380e1767b2f8b9883f3ae9d6952c78ac85e718732fd78a275b5e4d2551e8aced99c9e
6
+ metadata.gz: 5bd7e39538dbe10be10f4b41bda52e2960ded638f56cb9bbd817db914f48b67f473cba0bc7075d9b5f5f9972c6c86b8560449f6722959a3cc1cf201060cb8fb5
7
+ data.tar.gz: 4adccda76f55f41c409bfa9cdf972e966ee7a2225bb1784672712f1191c86cd8bb8acb57c0c8c902477ac1219f68f2c7b9547abf084ccd0e4c713cb99cfebf72
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'sqlite3'
30
30
  spec.add_development_dependency 'database_cleaner'
31
31
  spec.add_development_dependency 'appraisal'
32
+ spec.add_development_dependency 'pry-byebug'
32
33
  end
@@ -8,16 +8,39 @@ module CacheDependsOn
8
8
  included do
9
9
  cattr_accessor(:invalidates_cache_of) { [] }
10
10
 
11
- after_commit { invalidate_dependent_caches }
11
+ after_commit { invalidate_marked_dependent_caches }
12
+
13
+ after_touch { invalidate_dependent_caches_after_outermost_transaction }
14
+
15
+ after_save { invalidate_dependent_caches_after_outermost_transaction }
16
+
17
+ after_destroy { invalidate_dependent_caches_after_outermost_transaction }
12
18
 
13
19
  define_model_callbacks :cache_invalidation
14
20
  end
15
21
 
22
+ def invalidate_after_outermost_transaction
23
+ self.marked_to_be_invalidated_after_outermost_transaction = true
24
+ invalidate_dependent_caches_after_outermost_transaction
25
+ end
26
+
16
27
  def invalidate_cache
17
- touch
28
+ if marked_to_be_invalidated_after_outermost_transaction
29
+ self.marked_to_be_invalidated_after_outermost_transaction = false
30
+ touch
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ attr_accessor :marked_to_be_invalidated_after_outermost_transaction
37
+
38
+ def invalidate_dependent_caches_after_outermost_transaction
39
+ invalidates_cache_of.select(&:collection?).each { |association| __send__(association.name).each(&:invalidate_after_outermost_transaction) }
40
+ invalidates_cache_of.reject(&:collection?).each { |association| __send__(association.name).try(:invalidate_after_outermost_transaction) }
18
41
  end
19
42
 
20
- def invalidate_dependent_caches
43
+ def invalidate_marked_dependent_caches
21
44
  run_callbacks(:cache_invalidation) do
22
45
  invalidates_cache_of.select(&:collection?).each { |association| __send__(association.name).each(&:invalidate_cache) }
23
46
  invalidates_cache_of.reject(&:collection?).each { |association| __send__(association.name).try(:invalidate_cache) }
@@ -6,12 +6,12 @@ module CacheDependsOn
6
6
  attr_reader :model_klass
7
7
 
8
8
  def define_cache_dependency_on(association_names)
9
- model_klass.class_eval { include ActiveRecordModelExtension }
10
-
11
9
  find_associations_by_names(association_names).each do |association|
12
10
  association.klass.class_eval { include ActiveRecordModelExtension }
13
11
  association.klass.invalidates_cache_of << find_inverse_of(association)
14
12
  end
13
+
14
+ model_klass.class_eval { include ActiveRecordModelExtension }
15
15
  end
16
16
 
17
17
  private
@@ -1,3 +1,3 @@
1
1
  module CacheDependsOn
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_depends_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vartanov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: pry-byebug
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
117
131
  description: 'A better way of controlling cache dependencies than ''belongs_to :product,
118
132
  touch: true'''
119
133
  email: