active_model_cachers 2.1.7 → 2.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +59 -0
- data/.gitignore +9 -9
- data/CHANGELOG.md +71 -67
- data/CODE_OF_CONDUCT.md +48 -48
- data/LICENSE.txt +21 -21
- data/README.md +399 -390
- data/Rakefile +10 -10
- data/active_model_cachers.gemspec +45 -45
- 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 -11
- data/lib/active_model_cachers/active_record/attr_model.rb +124 -124
- data/lib/active_model_cachers/active_record/cacher.rb +97 -97
- data/lib/active_model_cachers/active_record/extension.rb +119 -119
- data/lib/active_model_cachers/active_record/global_callbacks.rb +67 -67
- data/lib/active_model_cachers/cache_service.rb +151 -151
- data/lib/active_model_cachers/cache_service_factory.rb +55 -55
- data/lib/active_model_cachers/column_value_cache.rb +47 -47
- 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/patches/patch_rails_3.rb +49 -49
- data/lib/active_model_cachers/patches/uninitialized_attribute.rb +9 -9
- data/lib/active_model_cachers/version.rb +4 -4
- metadata +12 -7
- data/.travis.yml +0 -33
@@ -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.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
|
+
# 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,9 +1,9 @@
|
|
1
|
-
if defined?(ActiveRecord::Attribute)
|
2
|
-
class ActiveRecord::Attribute
|
3
|
-
class Uninitialized < self
|
4
|
-
def forgetting_assignment
|
5
|
-
dup
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
if defined?(ActiveRecord::Attribute)
|
2
|
+
class ActiveRecord::Attribute
|
3
|
+
class Uninitialized < self
|
4
|
+
def forgetting_assignment
|
5
|
+
dup
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
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,14 +1,14 @@
|
|
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
|
@@ -76,16 +76,22 @@ dependencies:
|
|
76
76
|
name: request_store
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: 1.4.0
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.6.0
|
82
85
|
type: :runtime
|
83
86
|
prerelease: false
|
84
87
|
version_requirements: !ruby/object:Gem::Requirement
|
85
88
|
requirements:
|
86
|
-
- - "
|
89
|
+
- - ">="
|
87
90
|
- !ruby/object:Gem::Version
|
88
91
|
version: 1.4.0
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.6.0
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
96
|
name: activerecord
|
91
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,8 +114,8 @@ executables: []
|
|
108
114
|
extensions: []
|
109
115
|
extra_rdoc_files: []
|
110
116
|
files:
|
117
|
+
- ".github/workflows/ruby.yml"
|
111
118
|
- ".gitignore"
|
112
|
-
- ".travis.yml"
|
113
119
|
- CHANGELOG.md
|
114
120
|
- CODE_OF_CONDUCT.md
|
115
121
|
- LICENSE.txt
|
@@ -165,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
171
|
- !ruby/object:Gem::Version
|
166
172
|
version: '0'
|
167
173
|
requirements: []
|
168
|
-
|
169
|
-
rubygems_version: 2.6.14
|
174
|
+
rubygems_version: 3.2.14
|
170
175
|
signing_key:
|
171
176
|
specification_version: 4
|
172
177
|
summary: Simply cache whatever you want by using cachers. Support Rails 3, 4, 5.
|