active_model_cachers 2.1.3 → 2.1.8
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +59 -0
- data/.gitignore +9 -9
- data/CHANGELOG.md +71 -50
- data/CODE_OF_CONDUCT.md +48 -48
- data/LICENSE.txt +21 -21
- data/README.md +399 -353
- data/Rakefile +10 -10
- data/active_model_cachers.gemspec +45 -38
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/gemfiles/3.2.gemfile +11 -11
- data/gemfiles/4.2.gemfile +11 -11
- data/gemfiles/5.0.gemfile +11 -11
- data/gemfiles/5.1.gemfile +11 -11
- data/gemfiles/5.2.gemfile +11 -11
- data/gemfiles/6.0.gemfile +11 -0
- data/lib/active_model_cachers.rb +11 -0
- data/lib/active_model_cachers/active_record/attr_model.rb +124 -103
- data/lib/active_model_cachers/active_record/cacher.rb +97 -96
- data/lib/active_model_cachers/active_record/extension.rb +119 -106
- data/lib/active_model_cachers/active_record/global_callbacks.rb +67 -59
- data/lib/active_model_cachers/cache_service.rb +151 -134
- data/lib/active_model_cachers/cache_service_factory.rb +55 -55
- data/lib/active_model_cachers/column_value_cache.rb +47 -46
- data/lib/active_model_cachers/config.rb +6 -6
- data/lib/active_model_cachers/false_object.rb +5 -5
- data/lib/active_model_cachers/hook/associations.rb +43 -43
- data/lib/active_model_cachers/hook/dependencies.rb +38 -38
- data/lib/active_model_cachers/hook/on_model_delete.rb +29 -29
- data/lib/active_model_cachers/nil_object.rb +5 -5
- data/lib/active_model_cachers/{active_record → patches}/patch_rails_3.rb +49 -49
- data/lib/active_model_cachers/patches/uninitialized_attribute.rb +9 -0
- data/lib/active_model_cachers/version.rb +4 -4
- metadata +31 -13
- data/.travis.yml +0 -26
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelCachers
|
3
|
-
class Config
|
4
|
-
attr_accessor :store
|
5
|
-
end
|
6
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveModelCachers
|
3
|
+
class Config
|
4
|
+
attr_accessor :store
|
5
|
+
end
|
6
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelCachers
|
3
|
-
class FalseObject
|
4
|
-
end
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveModelCachers
|
3
|
+
class FalseObject
|
4
|
+
end
|
5
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'active_record'
|
3
|
-
require 'active_record/associations/has_many_association'
|
4
|
-
require 'active_model_cachers/hook/on_model_delete'
|
5
|
-
|
6
|
-
module ActiveModelCachers::Hook
|
7
|
-
module Associations
|
8
|
-
def delete_count(method, scope)
|
9
|
-
if method == :delete_all
|
10
|
-
# TODO:
|
11
|
-
else # nullify
|
12
|
-
call_hooks{ scope.pluck(:id) }
|
13
|
-
end
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def delete_records(records, method)
|
18
|
-
case method
|
19
|
-
when :destroy
|
20
|
-
when :delete_all
|
21
|
-
# TODO:
|
22
|
-
else
|
23
|
-
call_hooks{ records.map(&:id) }
|
24
|
-
end
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def call_hooks(&get_ids)
|
31
|
-
ids = nil
|
32
|
-
get_ids_with_cache = ->{ ids ||= get_ids.call }
|
33
|
-
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.on_nullify.exec(
|
34
|
-
self,
|
35
|
-
reflection.klass,
|
36
|
-
reflection.foreign_key,
|
37
|
-
get_ids_with_cache,
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
ActiveRecord::Associations::HasManyAssociation.send(:prepend, ActiveModelCachers::Hook::Associations)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_record/associations/has_many_association'
|
4
|
+
require 'active_model_cachers/hook/on_model_delete'
|
5
|
+
|
6
|
+
module ActiveModelCachers::Hook
|
7
|
+
module Associations
|
8
|
+
def delete_count(method, scope)
|
9
|
+
if method == :delete_all
|
10
|
+
# TODO:
|
11
|
+
else # nullify
|
12
|
+
call_hooks{ scope.pluck(:id) }
|
13
|
+
end
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_records(records, method)
|
18
|
+
case method
|
19
|
+
when :destroy
|
20
|
+
when :delete_all
|
21
|
+
# TODO:
|
22
|
+
else
|
23
|
+
call_hooks{ records.map(&:id) }
|
24
|
+
end
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def call_hooks(&get_ids)
|
31
|
+
ids = nil
|
32
|
+
get_ids_with_cache = ->{ ids ||= get_ids.call }
|
33
|
+
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.on_nullify.exec(
|
34
|
+
self,
|
35
|
+
reflection.klass,
|
36
|
+
reflection.foreign_key,
|
37
|
+
get_ids_with_cache,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
ActiveRecord::Associations::HasManyAssociation.send(:prepend, ActiveModelCachers::Hook::Associations)
|
@@ -1,38 +1,38 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'active_support/dependencies'
|
3
|
-
|
4
|
-
module ActiveModelCachers::Hook
|
5
|
-
module Depdenencies
|
6
|
-
def onload(const_name, times: 1, &block)
|
7
|
-
const = const_name if not const_name.is_a?(String)
|
8
|
-
if const or Module.const_defined?(const_name)
|
9
|
-
(const || const_name.constantize).instance_exec(&block)
|
10
|
-
else
|
11
|
-
load_hooks[const_name].push(block: block, times: times)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_hooks
|
16
|
-
@load_hooks ||= Hash.new{|h, k| h[k] = [] }
|
17
|
-
end
|
18
|
-
|
19
|
-
def new_constants_in(*)
|
20
|
-
new_constants = super.each do |const_name|
|
21
|
-
hooks = load_hooks[const_name]
|
22
|
-
need_compact = false
|
23
|
-
hooks.each_with_index do |hook, idx|
|
24
|
-
if (hook[:times] -= 1) < 0
|
25
|
-
hooks[idx] = nil
|
26
|
-
need_compact = true
|
27
|
-
next
|
28
|
-
end
|
29
|
-
const_name.constantize.instance_exec(&hook[:block])
|
30
|
-
end
|
31
|
-
hooks.compact! if need_compact
|
32
|
-
end
|
33
|
-
return new_constants
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
ActiveSupport::Dependencies.send(:extend, ActiveModelCachers::Hook::Depdenencies)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
|
4
|
+
module ActiveModelCachers::Hook
|
5
|
+
module Depdenencies
|
6
|
+
def onload(const_name, times: 1, &block)
|
7
|
+
const = const_name if not const_name.is_a?(String)
|
8
|
+
if const or Module.const_defined?(const_name)
|
9
|
+
(const || const_name.constantize).instance_exec(&block)
|
10
|
+
else
|
11
|
+
load_hooks[const_name].push(block: block, times: times)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_hooks
|
16
|
+
@load_hooks ||= Hash.new{|h, k| h[k] = [] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_constants_in(*)
|
20
|
+
new_constants = super.each do |const_name|
|
21
|
+
hooks = load_hooks[const_name]
|
22
|
+
need_compact = false
|
23
|
+
hooks.each_with_index do |hook, idx|
|
24
|
+
if (hook[:times] -= 1) < 0
|
25
|
+
hooks[idx] = nil
|
26
|
+
need_compact = true
|
27
|
+
next
|
28
|
+
end
|
29
|
+
const_name.constantize.instance_exec(&hook[:block])
|
30
|
+
end
|
31
|
+
hooks.compact! if need_compact
|
32
|
+
end
|
33
|
+
return new_constants
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ActiveSupport::Dependencies.send(:extend, ActiveModelCachers::Hook::Depdenencies)
|
@@ -1,29 +1,29 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'active_record'
|
3
|
-
|
4
|
-
module ActiveModelCachers::Hook
|
5
|
-
module OnModelDelete
|
6
|
-
module InstanceMethods
|
7
|
-
def delete
|
8
|
-
self.class.delete(id, self) if persisted?
|
9
|
-
@destroyed = true
|
10
|
-
freeze
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module ClassMethods
|
15
|
-
def delete(id, model = nil)
|
16
|
-
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.
|
17
|
-
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.
|
18
|
-
|
19
|
-
result = super(id)
|
20
|
-
|
21
|
-
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.after_delete.exec(self, self, id, model)
|
22
|
-
return result
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
ActiveRecord::Base.send(:include, ActiveModelCachers::Hook::OnModelDelete::InstanceMethods)
|
29
|
-
ActiveRecord::Base.send(:extend, ActiveModelCachers::Hook::OnModelDelete::ClassMethods)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module ActiveModelCachers::Hook
|
5
|
+
module OnModelDelete
|
6
|
+
module InstanceMethods
|
7
|
+
def delete
|
8
|
+
self.class.delete(id, self) if persisted?
|
9
|
+
@destroyed = true
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def delete(id, model = nil)
|
16
|
+
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.before_delete1.exec(self, self, id, model)
|
17
|
+
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.before_delete2.exec(self, self, id, model)
|
18
|
+
|
19
|
+
result = super(id)
|
20
|
+
|
21
|
+
ActiveModelCachers::ActiveRecord::Extension.global_callbacks.after_delete.exec(self, self, id, model)
|
22
|
+
return result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveRecord::Base.send(:include, ActiveModelCachers::Hook::OnModelDelete::InstanceMethods)
|
29
|
+
ActiveRecord::Base.send(:extend, ActiveModelCachers::Hook::OnModelDelete::ClassMethods)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelCachers
|
3
|
-
class NilObject
|
4
|
-
end
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveModelCachers
|
3
|
+
class NilObject
|
4
|
+
end
|
5
|
+
end
|
@@ -1,49 +1,49 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelCachers
|
3
|
-
module ActiveRecord
|
4
|
-
module Extension
|
5
|
-
# define #find_by for Rails 3
|
6
|
-
def find_by(*args)
|
7
|
-
where(*args).order('').first
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ActiveRecord
|
14
|
-
module Transactions
|
15
|
-
if not method_defined?(:transaction_include_any_action?)
|
16
|
-
def transaction_include_any_action?(fire_on)
|
17
|
-
fire_on.any?{|s| transaction_include_action?(s) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module ActiveRecord
|
24
|
-
module Associations
|
25
|
-
# = Active Record Associations
|
26
|
-
#
|
27
|
-
# This is the root class of all associations ('+ Foo' signifies an included module Foo):
|
28
|
-
#
|
29
|
-
# Association
|
30
|
-
# SingularAssociation
|
31
|
-
# HasOneAssociation
|
32
|
-
# HasOneThroughAssociation + ThroughAssociation
|
33
|
-
# BelongsToAssociation
|
34
|
-
# BelongsToPolymorphicAssociation
|
35
|
-
# CollectionAssociation
|
36
|
-
# HasAndBelongsToManyAssociation
|
37
|
-
# HasManyAssociation
|
38
|
-
# HasManyThroughAssociation + ThroughAssociation
|
39
|
-
class Association #:nodoc:
|
40
|
-
alias_method :scope, :scoped
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class ActiveModelCachers::ColumnValueCache
|
46
|
-
def pluck_columns(object, relation, columns)
|
47
|
-
object.connection.select_all(relation.select(columns)).map(&:values)
|
48
|
-
end
|
49
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveModelCachers
|
3
|
+
module ActiveRecord
|
4
|
+
module Extension
|
5
|
+
# define #find_by for Rails 3
|
6
|
+
def find_by(*args)
|
7
|
+
where(*args).order('').first
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ActiveRecord
|
14
|
+
module Transactions
|
15
|
+
if not method_defined?(:transaction_include_any_action?)
|
16
|
+
def transaction_include_any_action?(fire_on)
|
17
|
+
fire_on.any?{|s| transaction_include_action?(s) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ActiveRecord
|
24
|
+
module Associations
|
25
|
+
# = Active Record Associations
|
26
|
+
#
|
27
|
+
# This is the root class of all associations ('+ Foo' signifies an included module Foo):
|
28
|
+
#
|
29
|
+
# Association
|
30
|
+
# SingularAssociation
|
31
|
+
# HasOneAssociation
|
32
|
+
# HasOneThroughAssociation + ThroughAssociation
|
33
|
+
# BelongsToAssociation
|
34
|
+
# BelongsToPolymorphicAssociation
|
35
|
+
# CollectionAssociation
|
36
|
+
# HasAndBelongsToManyAssociation
|
37
|
+
# HasManyAssociation
|
38
|
+
# HasManyThroughAssociation + ThroughAssociation
|
39
|
+
class Association #:nodoc:
|
40
|
+
alias_method :scope, :scoped
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class ActiveModelCachers::ColumnValueCache
|
46
|
+
def pluck_columns(object, relation, columns)
|
47
|
+
object.connection.select_all(relation.select(columns)).map(&:values)
|
48
|
+
end
|
49
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelCachers
|
3
|
-
VERSION = '2.1.
|
4
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ActiveModelCachers
|
3
|
+
VERSION = '2.1.8'
|
4
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_cachers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 3.x
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.17'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: 3.x
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +76,22 @@ dependencies:
|
|
70
76
|
name: request_store
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - "
|
79
|
+
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: 1.4.0
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.6.0
|
76
85
|
type: :runtime
|
77
86
|
prerelease: false
|
78
87
|
version_requirements: !ruby/object:Gem::Requirement
|
79
88
|
requirements:
|
80
|
-
- - "
|
89
|
+
- - ">="
|
81
90
|
- !ruby/object:Gem::Version
|
82
91
|
version: 1.4.0
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.6.0
|
83
95
|
- !ruby/object:Gem::Dependency
|
84
96
|
name: activerecord
|
85
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,8 +114,8 @@ executables: []
|
|
102
114
|
extensions: []
|
103
115
|
extra_rdoc_files: []
|
104
116
|
files:
|
117
|
+
- ".github/workflows/ruby.yml"
|
105
118
|
- ".gitignore"
|
106
|
-
- ".travis.yml"
|
107
119
|
- CHANGELOG.md
|
108
120
|
- CODE_OF_CONDUCT.md
|
109
121
|
- LICENSE.txt
|
@@ -117,12 +129,12 @@ files:
|
|
117
129
|
- gemfiles/5.0.gemfile
|
118
130
|
- gemfiles/5.1.gemfile
|
119
131
|
- gemfiles/5.2.gemfile
|
132
|
+
- gemfiles/6.0.gemfile
|
120
133
|
- lib/active_model_cachers.rb
|
121
134
|
- lib/active_model_cachers/active_record/attr_model.rb
|
122
135
|
- lib/active_model_cachers/active_record/cacher.rb
|
123
136
|
- lib/active_model_cachers/active_record/extension.rb
|
124
137
|
- lib/active_model_cachers/active_record/global_callbacks.rb
|
125
|
-
- lib/active_model_cachers/active_record/patch_rails_3.rb
|
126
138
|
- lib/active_model_cachers/cache_service.rb
|
127
139
|
- lib/active_model_cachers/cache_service_factory.rb
|
128
140
|
- lib/active_model_cachers/column_value_cache.rb
|
@@ -132,11 +144,18 @@ files:
|
|
132
144
|
- lib/active_model_cachers/hook/dependencies.rb
|
133
145
|
- lib/active_model_cachers/hook/on_model_delete.rb
|
134
146
|
- lib/active_model_cachers/nil_object.rb
|
147
|
+
- lib/active_model_cachers/patches/patch_rails_3.rb
|
148
|
+
- lib/active_model_cachers/patches/uninitialized_attribute.rb
|
135
149
|
- lib/active_model_cachers/version.rb
|
136
150
|
homepage: https://github.com/khiav223577/active_model_cachers
|
137
151
|
licenses:
|
138
152
|
- MIT
|
139
|
-
metadata:
|
153
|
+
metadata:
|
154
|
+
homepage_uri: https://github.com/khiav223577/active_model_cachers
|
155
|
+
changelog_uri: https://github.com/khiav223577/active_model_cachers/blob/master/CHANGELOG.md
|
156
|
+
source_code_uri: https://github.com/khiav223577/active_model_cachers
|
157
|
+
documentation_uri: https://www.rubydoc.info/gems/active_model_cachers
|
158
|
+
bug_tracker_uri: https://github.com/khiav223577/active_model_cachers/issues
|
140
159
|
post_install_message:
|
141
160
|
rdoc_options: []
|
142
161
|
require_paths:
|
@@ -152,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
171
|
- !ruby/object:Gem::Version
|
153
172
|
version: '0'
|
154
173
|
requirements: []
|
155
|
-
|
156
|
-
rubygems_version: 2.7.6
|
174
|
+
rubygems_version: 3.2.14
|
157
175
|
signing_key:
|
158
176
|
specification_version: 4
|
159
177
|
summary: Simply cache whatever you want by using cachers. Support Rails 3, 4, 5.
|