activerecord-redundancy 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redundancy.rb +16 -11
- data/lib/redundancy/update_base.rb +68 -40
- data/lib/redundancy/update_column.rb +2 -0
- data/lib/redundancy/update_column_with_prev.rb +27 -0
- data/lib/redundancy/update_method_with_prev.rb +34 -0
- data/lib/redundancy/utils.rb +48 -27
- data/lib/redundancy/version.rb +1 -1
- data/test/cache_column/has_many_belongs_to_association_test.rb +1 -1
- data/test/cache_column/has_one_through_belongs_to_association_test.rb +44 -0
- data/test/cache_column/options_test.rb +2 -2
- data/test/fixtures/posts.yml +2 -0
- data/test/support/environment.rb +19 -11
- data/test/support/models/account.rb +2 -0
- data/test/support/models/post.rb +3 -0
- data/test/support/models/session.rb +3 -0
- data/test/support/models/user.rb +2 -1
- metadata +37 -7
- data/lib/redundancy/update_method.rb +0 -19
- data/lib/redundancy/update_prev_column.rb +0 -19
- data/lib/redundancy/update_prev_method.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a99315b6ab5b75fa9f75e316eb1b89eaeee46ce
|
4
|
+
data.tar.gz: a1924f47a0babed76fc894152b49b3c20f759770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28a0907c6d60ab12ec1fea777be6a0c067289074b436d3a689fe5482c9c5cb7a10001cf7b50aa611b74ec8f51f3ead6d551ccc5a73933c35d6804fb32eef1c0
|
7
|
+
data.tar.gz: 32ba11f593050aa82759c59ef6cc381f9f1243004ecb48838c09eb864b8898e89915a3a601309bfa99d2c6442cb37c987dbb71e257e384c899dba1c1809ca66f
|
data/lib/redundancy.rb
CHANGED
@@ -3,6 +3,19 @@ require 'redundancy/utils'
|
|
3
3
|
module Redundancy
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
def self.update_redundancies
|
7
|
+
ActiveRecord::Base.subclasses.each do |klass|
|
8
|
+
klass.try :update_redundancies
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_redundancies
|
13
|
+
self.class.redundancies.each do |redundancy|
|
14
|
+
redundancy.force_update!(self)
|
15
|
+
end
|
16
|
+
save(validate: false)
|
17
|
+
end
|
18
|
+
|
6
19
|
included do
|
7
20
|
before_save :update_redundancies_before_save
|
8
21
|
after_save :update_redundancies_after_save
|
@@ -22,20 +35,14 @@ module Redundancy
|
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
25
|
-
def update_redundancies
|
26
|
-
self.class.redundancies.each do |redundancy|
|
27
|
-
redundancy.force_update!(self)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
38
|
module ClassMethods
|
32
39
|
def cache_column association, attribute, options = {}
|
33
|
-
options.assert_valid_keys(:cache_column, :
|
40
|
+
options.assert_valid_keys(:cache_column, :default)
|
34
41
|
Utils.cache_column self, association, attribute, options
|
35
42
|
end
|
36
43
|
|
37
44
|
def cache_method association, attribute, options = {}
|
38
|
-
options.assert_valid_keys(:
|
45
|
+
options.assert_valid_keys(:cache_method)
|
39
46
|
Utils.cache_method self, association, attribute, options
|
40
47
|
end
|
41
48
|
|
@@ -45,9 +52,7 @@ module Redundancy
|
|
45
52
|
|
46
53
|
def update_redundancies
|
47
54
|
all.each do |record|
|
48
|
-
|
49
|
-
redundancy.force_update!(record)
|
50
|
-
end
|
55
|
+
record.update_redundancies
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
@@ -2,89 +2,117 @@ module Redundancy
|
|
2
2
|
|
3
3
|
class UpdateBase
|
4
4
|
attr_reader :options
|
5
|
-
attr_reader :source, :dest, :
|
6
|
-
attr_reader :
|
7
|
-
attr_reader :target, :value
|
5
|
+
attr_reader :klass, :source, :dest, :change_if
|
6
|
+
attr_reader :context
|
8
7
|
|
9
8
|
def initialize options
|
10
9
|
@options = options
|
11
|
-
@source, @dest = options[:source], options[:dest]
|
12
10
|
@klass = options[:klass]
|
13
|
-
|
11
|
+
@source, @dest = options[:source], options[:dest]
|
14
12
|
@change_if = options[:change_if]
|
15
13
|
@update = options[:update] || false
|
14
|
+
|
15
|
+
cleanup_context
|
16
16
|
end
|
17
17
|
|
18
18
|
def force_update! record
|
19
|
-
|
20
|
-
@update = true
|
21
|
-
before_save record
|
22
|
-
after_save record
|
19
|
+
set_context :force, true
|
23
20
|
end
|
24
21
|
|
22
|
+
# ActiveRecord Hooks
|
25
23
|
def before_save record
|
26
24
|
end
|
27
25
|
|
28
26
|
def after_save record
|
29
27
|
end
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
protected
|
30
|
+
|
31
|
+
# Context
|
32
|
+
def set_context key, value
|
33
|
+
@context[key] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def cleanup_context
|
37
|
+
@context = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def update
|
41
|
+
@context[:update] || @update
|
42
|
+
end
|
43
|
+
|
44
|
+
def force
|
45
|
+
@context[:force]
|
33
46
|
end
|
34
47
|
|
35
|
-
def
|
36
|
-
|
37
|
-
return unless prev_id
|
38
|
-
@target = dest[:klass].where(id: prev_id)
|
48
|
+
def update_method
|
49
|
+
@context[:update_method] || (update ? :update_attribute : :write_attribute)
|
39
50
|
end
|
40
51
|
|
41
|
-
def
|
42
|
-
@
|
52
|
+
def context key
|
53
|
+
@context[key]
|
43
54
|
end
|
44
55
|
|
45
|
-
def
|
46
|
-
|
47
|
-
@value = value && source[:attribute] && value.send(source[:attribute])
|
48
|
-
@value = nil if source[:nil_unless] && !record.send(source[:nil_unless])
|
49
|
-
@value
|
56
|
+
def get_target_from_association record, key = :default
|
57
|
+
set_context :"target_#{key}", dest[:association] ? record.send(dest[:association]) : record
|
50
58
|
end
|
51
59
|
|
52
|
-
def
|
53
|
-
|
60
|
+
def get_target_from_prev_association record, key = :default
|
61
|
+
set_context :"target_#{key}", record.send(:attribute_was, dest[:association])
|
54
62
|
end
|
55
63
|
|
56
|
-
def
|
57
|
-
|
64
|
+
def get_target_from_foreign_key record, key = :default
|
65
|
+
id = record.send(:attribute_was, dest[:foreign_key])
|
66
|
+
return unless id
|
67
|
+
set_context :"target_#{key}", dest[:klass].where(id: id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_target_from_relation_first_record key = :default
|
71
|
+
target = context(:"target_#{key}")
|
72
|
+
set_context :"target_#{key}", target.first if target.kind_of? ActiveRecord::Relation
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_value_from_association record, key = :default
|
76
|
+
value = source[:association] ? record.send(source[:association]) : record
|
77
|
+
value = value && source[:attribute] && value.send(source[:attribute])
|
78
|
+
value = nil if source[:nil_unless] && !record.send(source[:nil_unless])
|
79
|
+
set_context :"value_#{key}", value
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_value_from_default record, key = :default
|
83
|
+
set_context :"value_#{key}", source[:default]
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_value_from_target record, key = :default
|
87
|
+
target = context(:"target_#{key}")
|
88
|
+
set_context :"value_#{key}", target && source[:attribute] && target.send(source[:attribute])
|
58
89
|
end
|
59
90
|
|
60
91
|
def raise_if_class_mismatch record
|
61
92
|
raise ArgumentError, "record class mismatch, expected #{klass}, got #{record.class}" unless record.kind_of? klass
|
62
93
|
end
|
63
94
|
|
64
|
-
def update_target record
|
95
|
+
def update_target record, key = :default
|
96
|
+
target = context(:"target_#{key}")
|
97
|
+
value = context(:"value_#{key}")
|
98
|
+
|
65
99
|
case target
|
66
100
|
when ActiveRecord::Base
|
67
101
|
return if target.send(:read_attribute, dest[:attribute]) == value
|
68
|
-
log "#{
|
69
|
-
|
70
|
-
if update
|
71
|
-
target.send(:update_attribute, dest[:attribute], value)
|
72
|
-
else
|
73
|
-
target.send(:write_attribute, dest[:attribute], value)
|
74
|
-
end
|
102
|
+
log "#{update_method} #{target.class}(#{target.id})##{dest[:attribute]} with #{value.inspect}"
|
103
|
+
target.send(update_method, dest[:attribute], value)
|
75
104
|
when ActiveRecord::Relation
|
76
|
-
log "
|
105
|
+
log "update_all #{target.class}##{dest[:attribute]} with #{value.inspect}"
|
77
106
|
target.send(:update_all, dest[:attribute] => value)
|
78
107
|
end
|
79
108
|
end
|
80
109
|
|
81
|
-
def
|
82
|
-
|
83
|
-
update_target record
|
110
|
+
def need_update? record
|
111
|
+
force || !change_if || record.send(:attribute_changed?, change_if)
|
84
112
|
end
|
85
113
|
|
86
|
-
def
|
87
|
-
|
114
|
+
def foreign_key_changed? record
|
115
|
+
record.send(:attribute_changed?, dest[:foreign_key])
|
88
116
|
end
|
89
117
|
|
90
118
|
# require 'colorize'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'redundancy/update_base'
|
2
|
+
|
3
|
+
module Redundancy
|
4
|
+
|
5
|
+
class UpdateColumnWithPrev < UpdateBase
|
6
|
+
|
7
|
+
def before_save record
|
8
|
+
raise_if_class_mismatch record
|
9
|
+
return unless need_update? record
|
10
|
+
|
11
|
+
get_target_from_association record
|
12
|
+
get_value_from_association record
|
13
|
+
|
14
|
+
update_target record
|
15
|
+
|
16
|
+
return unless foreign_key_changed? record
|
17
|
+
get_target_from_foreign_key record, :prev
|
18
|
+
get_value_from_default record, :prev
|
19
|
+
|
20
|
+
update_target record, :prev
|
21
|
+
ensure
|
22
|
+
cleanup_context
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'redundancy/update_base'
|
2
|
+
|
3
|
+
module Redundancy
|
4
|
+
|
5
|
+
class UpdateMethodWithPrev < UpdateBase
|
6
|
+
|
7
|
+
def before_save record
|
8
|
+
raise_if_class_mismatch record
|
9
|
+
return unless foreign_key_changed? record
|
10
|
+
|
11
|
+
get_target_from_foreign_key record, :prev
|
12
|
+
get_target_from_relation_first_record :prev
|
13
|
+
end
|
14
|
+
|
15
|
+
def after_save record
|
16
|
+
return unless need_update? record
|
17
|
+
set_context :update_method, :update_column
|
18
|
+
|
19
|
+
get_target_from_association record
|
20
|
+
get_value_from_target record
|
21
|
+
|
22
|
+
update_target record
|
23
|
+
|
24
|
+
return unless context(:"target_prev")
|
25
|
+
|
26
|
+
get_value_from_target record, :prev
|
27
|
+
update_target record, :prev
|
28
|
+
ensure
|
29
|
+
cleanup_context
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/redundancy/utils.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'redundancy/update_column'
|
2
|
-
require 'redundancy/
|
3
|
-
require 'redundancy/
|
4
|
-
require 'redundancy/update_prev_method'
|
2
|
+
require 'redundancy/update_column_with_prev'
|
3
|
+
require 'redundancy/update_method_with_prev'
|
5
4
|
|
6
5
|
module Redundancy
|
7
6
|
|
@@ -17,7 +16,7 @@ module Redundancy
|
|
17
16
|
foreign_key = reflection.foreign_key
|
18
17
|
remote_klass = reflection.klass
|
19
18
|
|
20
|
-
inverse_association = get_inverse_association local_klass, remote_klass, options
|
19
|
+
inverse_association = get_inverse_association local_klass, remote_klass, reflection.options
|
21
20
|
|
22
21
|
cache_column = options[:cache_column] || :"#{association}_#{attribute}"
|
23
22
|
|
@@ -30,17 +29,44 @@ module Redundancy
|
|
30
29
|
)
|
31
30
|
|
32
31
|
when :has_one
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
if reflection.through_reflection
|
33
|
+
|
34
|
+
through_reflection = reflection.through_reflection
|
35
|
+
if through_reflection.through_reflection
|
36
|
+
raise ArgumentError, "Multi level has_one through reflection is not support yet!"
|
37
|
+
end
|
38
|
+
|
39
|
+
through_foreign_key = through_reflection.foreign_key
|
40
|
+
through_remote_klass = through_reflection.klass
|
41
|
+
through_association = reflection.source_reflection_name
|
42
|
+
through_inverse_association = get_inverse_association local_klass, through_remote_klass
|
43
|
+
|
44
|
+
case through_reflection.macro
|
45
|
+
when :belongs_to
|
46
|
+
local_klass.redundancies << UpdateColumn.new(
|
47
|
+
source: { association: association, attribute: attribute },
|
48
|
+
dest: { association: nil, attribute: cache_column },
|
49
|
+
change_if: through_foreign_key, klass: local_klass
|
50
|
+
)
|
51
|
+
|
52
|
+
when :has_one
|
53
|
+
raise ArgumentError, "has_one through has_one reflection is not support yet!"
|
54
|
+
end
|
55
|
+
|
56
|
+
through_remote_klass.redundancies << UpdateColumn.new(
|
57
|
+
source: { association: through_association, attribute: attribute },
|
58
|
+
dest: { association: through_inverse_association, attribute: cache_column },
|
59
|
+
change_if: foreign_key, klass: through_remote_klass
|
60
|
+
)
|
61
|
+
|
62
|
+
else
|
63
|
+
remote_klass.redundancies << UpdateColumnWithPrev.new(
|
64
|
+
source: { association: nil, attribute: attribute, nil_unless: foreign_key, default: options[:default] },
|
65
|
+
dest: { klass: local_klass, foreign_key: foreign_key, association: inverse_association, attribute: cache_column },
|
66
|
+
change_if: foreign_key, klass: remote_klass
|
67
|
+
)
|
68
|
+
|
69
|
+
end
|
44
70
|
|
45
71
|
end
|
46
72
|
|
@@ -51,7 +77,7 @@ module Redundancy
|
|
51
77
|
)
|
52
78
|
end
|
53
79
|
|
54
|
-
def self.cache_method klass, association, attribute, options
|
80
|
+
def self.cache_method klass, association, attribute, options = {}
|
55
81
|
local_klass = klass
|
56
82
|
|
57
83
|
reflection = get_reflection local_klass, association
|
@@ -63,27 +89,23 @@ module Redundancy
|
|
63
89
|
|
64
90
|
cache_method = options[:cache_method] || :"raw_#{attribute}"
|
65
91
|
|
66
|
-
local_klass.redundancies <<
|
67
|
-
source: { attribute: cache_method },
|
68
|
-
dest: { association: association, attribute: attribute },
|
69
|
-
change_if: options[:change_if], klass: local_klass
|
70
|
-
)
|
71
|
-
|
72
|
-
local_klass.redundancies << UpdatePrevMethod.new(
|
92
|
+
local_klass.redundancies << UpdateMethodWithPrev.new(
|
73
93
|
source: { attribute: cache_method },
|
74
|
-
dest: { klass: remote_klass,
|
75
|
-
change_if:
|
94
|
+
dest: { klass: remote_klass, foreign_key: foreign_key, association: association, attribute: attribute },
|
95
|
+
change_if: nil, klass: local_klass
|
76
96
|
)
|
77
97
|
|
78
98
|
end
|
79
99
|
|
100
|
+
private
|
101
|
+
|
80
102
|
def self.get_reflection klass, association
|
81
103
|
reflection = klass.reflect_on_association(association)
|
82
104
|
raise ArgumentError, "Unknown association :#{association}" unless reflection
|
83
105
|
reflection
|
84
106
|
end
|
85
107
|
|
86
|
-
def self.get_inverse_association klass, reflection_klass, options
|
108
|
+
def self.get_inverse_association klass, reflection_klass, options = {}
|
87
109
|
model_name = klass.model_name
|
88
110
|
inverse_associations = options[:inverse_of]
|
89
111
|
inverse_associations ||= [model_name.plural, model_name.singular].map(&:to_sym)
|
@@ -96,7 +118,6 @@ module Redundancy
|
|
96
118
|
inverse_association
|
97
119
|
end
|
98
120
|
|
99
|
-
|
100
121
|
end
|
101
122
|
|
102
123
|
end
|
data/lib/redundancy/version.rb
CHANGED
@@ -54,7 +54,7 @@ class HasManyBelongsToAssociationTest < ActiveSupport::TestCase
|
|
54
54
|
assert_equal user.name, post.user_name
|
55
55
|
|
56
56
|
user.update_attribute(:name, "Other Name")
|
57
|
-
user.posts.each do |post|
|
57
|
+
user.posts.reload.each do |post|
|
58
58
|
assert_equal user.name, post.user_name
|
59
59
|
end
|
60
60
|
assert_equal user.name, post.reload.user_name
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HasOneThroughBelongsToAssociationTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
# has_one:through:belongs_to association
|
6
|
+
test "should update post.account_email when create post" do
|
7
|
+
account = accounts(:one)
|
8
|
+
user = users(:one)
|
9
|
+
post = Post.create(title: 'title', content: 'content', user: user)
|
10
|
+
assert_equal account.email, post.account_email
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should update post.account_email when update post.user" do
|
14
|
+
account = accounts(:one)
|
15
|
+
user = users(:one)
|
16
|
+
post = posts(:two)
|
17
|
+
assert_not_equal account.email, post.account_email
|
18
|
+
|
19
|
+
post.update_attribute(:user, user)
|
20
|
+
assert_equal account.email, post.account_email
|
21
|
+
assert_equal account.email, post.reload.account_email
|
22
|
+
end
|
23
|
+
|
24
|
+
test "should update post.account_email when update user.account" do
|
25
|
+
account = accounts(:one)
|
26
|
+
user = users(:two)
|
27
|
+
post = posts(:two)
|
28
|
+
assert_not_equal account.email, post.account_email
|
29
|
+
|
30
|
+
user.update_attribute(:account, account)
|
31
|
+
assert_equal account.email, post.reload.account_email
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should update post.account_email when update account.email" do
|
35
|
+
account = accounts(:one)
|
36
|
+
user = users(:one)
|
37
|
+
post = posts(:one)
|
38
|
+
assert_equal account.email, post.account_email
|
39
|
+
|
40
|
+
account.update_attribute(:email, "other@email.com")
|
41
|
+
assert_equal account.email, post.reload.account_email
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -6,7 +6,7 @@ class OptionsTest < ActiveSupport::TestCase
|
|
6
6
|
test "should update post.username when create post" do
|
7
7
|
user = users(:one)
|
8
8
|
post = Post.create(title: 'title', content: 'content', user: user)
|
9
|
-
assert_equal
|
9
|
+
assert_equal user.name, post.username
|
10
10
|
end
|
11
11
|
|
12
|
-
end
|
12
|
+
end
|
data/test/fixtures/posts.yml
CHANGED
data/test/support/environment.rb
CHANGED
@@ -12,16 +12,34 @@ ActiveRecord::Migration.verbose = false
|
|
12
12
|
ActiveRecord::Schema.define do
|
13
13
|
|
14
14
|
create_table "accounts", force: true do |t|
|
15
|
-
t.string "user_name"
|
16
15
|
t.string "email"
|
16
|
+
t.string "user_name"
|
17
|
+
t.string "session_name"
|
18
|
+
t.datetime "created_at"
|
19
|
+
t.datetime "updated_at"
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "users", force: true do |t|
|
23
|
+
t.integer "account_id"
|
24
|
+
t.string "account_email"
|
25
|
+
t.string "session_name"
|
26
|
+
t.integer "posts_count"
|
27
|
+
t.integer "posts_star"
|
28
|
+
t.string "name"
|
17
29
|
t.datetime "created_at"
|
18
30
|
t.datetime "updated_at"
|
19
31
|
end
|
20
32
|
|
33
|
+
create_table "sessions", force: true do |t|
|
34
|
+
t.integer "user_id"
|
35
|
+
t.string "name"
|
36
|
+
end
|
37
|
+
|
21
38
|
create_table "posts", force: true do |t|
|
22
39
|
t.integer "user_id"
|
23
40
|
t.string "user_name"
|
24
41
|
t.string "username"
|
42
|
+
t.string "account_email"
|
25
43
|
t.integer "star"
|
26
44
|
t.string "title"
|
27
45
|
t.text "content"
|
@@ -31,16 +49,6 @@ ActiveRecord::Schema.define do
|
|
31
49
|
|
32
50
|
add_index "posts", ["user_id"], name: "index_posts_on_user_id"
|
33
51
|
|
34
|
-
create_table "users", force: true do |t|
|
35
|
-
t.integer "account_id"
|
36
|
-
t.string "account_email"
|
37
|
-
t.integer "posts_count"
|
38
|
-
t.integer "posts_star"
|
39
|
-
t.string "name"
|
40
|
-
t.datetime "created_at"
|
41
|
-
t.datetime "updated_at"
|
42
|
-
end
|
43
|
-
|
44
52
|
end
|
45
53
|
|
46
54
|
autoload :Account, 'support/models/account'
|
data/test/support/models/post.rb
CHANGED
data/test/support/models/user.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-redundancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -44,6 +44,34 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: pry-byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
47
75
|
- !ruby/object:Gem::Dependency
|
48
76
|
name: pry-rescue
|
49
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,14 +127,14 @@ files:
|
|
99
127
|
- lib/redundancy.rb
|
100
128
|
- lib/redundancy/update_base.rb
|
101
129
|
- lib/redundancy/update_column.rb
|
102
|
-
- lib/redundancy/
|
103
|
-
- lib/redundancy/
|
104
|
-
- lib/redundancy/update_prev_method.rb
|
130
|
+
- lib/redundancy/update_column_with_prev.rb
|
131
|
+
- lib/redundancy/update_method_with_prev.rb
|
105
132
|
- lib/redundancy/utils.rb
|
106
133
|
- lib/redundancy/version.rb
|
107
134
|
- test/cache_column/belongs_to_has_one_association_test.rb
|
108
135
|
- test/cache_column/has_many_belongs_to_association_test.rb
|
109
136
|
- test/cache_column/has_one_belongs_to_association_test.rb
|
137
|
+
- test/cache_column/has_one_through_belongs_to_association_test.rb
|
110
138
|
- test/cache_column/options_test.rb
|
111
139
|
- test/cache_method/has_many_belongs_to_association_test.rb
|
112
140
|
- test/fixtures/accounts.yml
|
@@ -115,6 +143,7 @@ files:
|
|
115
143
|
- test/support/environment.rb
|
116
144
|
- test/support/models/account.rb
|
117
145
|
- test/support/models/post.rb
|
146
|
+
- test/support/models/session.rb
|
118
147
|
- test/support/models/user.rb
|
119
148
|
- test/test_helper.rb
|
120
149
|
homepage: https://github.com/bbtfr/activerecord-redundancy
|
@@ -137,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
166
|
version: '0'
|
138
167
|
requirements: []
|
139
168
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.5.1
|
141
170
|
signing_key:
|
142
171
|
specification_version: 4
|
143
172
|
summary: Redundancy for better performance, non painful
|
@@ -145,6 +174,7 @@ test_files:
|
|
145
174
|
- test/cache_column/belongs_to_has_one_association_test.rb
|
146
175
|
- test/cache_column/has_many_belongs_to_association_test.rb
|
147
176
|
- test/cache_column/has_one_belongs_to_association_test.rb
|
177
|
+
- test/cache_column/has_one_through_belongs_to_association_test.rb
|
148
178
|
- test/cache_column/options_test.rb
|
149
179
|
- test/cache_method/has_many_belongs_to_association_test.rb
|
150
180
|
- test/fixtures/accounts.yml
|
@@ -153,6 +183,6 @@ test_files:
|
|
153
183
|
- test/support/environment.rb
|
154
184
|
- test/support/models/account.rb
|
155
185
|
- test/support/models/post.rb
|
186
|
+
- test/support/models/session.rb
|
156
187
|
- test/support/models/user.rb
|
157
188
|
- test/test_helper.rb
|
158
|
-
has_rdoc:
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'redundancy/update_base'
|
2
|
-
|
3
|
-
module Redundancy
|
4
|
-
|
5
|
-
class UpdateMethod < UpdateBase
|
6
|
-
|
7
|
-
def after_save record
|
8
|
-
raise_if_class_mismatch record
|
9
|
-
return unless need_update? record
|
10
|
-
|
11
|
-
get_target_from_association record
|
12
|
-
get_value_from_target record
|
13
|
-
|
14
|
-
force_update_target record
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'redundancy/update_base'
|
2
|
-
|
3
|
-
module Redundancy
|
4
|
-
|
5
|
-
class UpdatePrevColumn < UpdateBase
|
6
|
-
|
7
|
-
def before_save record
|
8
|
-
raise_if_class_mismatch record
|
9
|
-
return unless need_update? record
|
10
|
-
|
11
|
-
get_target_from_prev_id record
|
12
|
-
get_value_from_source record
|
13
|
-
|
14
|
-
update_target record
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'redundancy/update_base'
|
2
|
-
|
3
|
-
module Redundancy
|
4
|
-
|
5
|
-
class UpdatePrevMethod < UpdateBase
|
6
|
-
|
7
|
-
def before_save record
|
8
|
-
raise_if_class_mismatch record
|
9
|
-
return unless need_update? record
|
10
|
-
|
11
|
-
get_target_from_prev_id record
|
12
|
-
get_target_from_relation_first_record
|
13
|
-
end
|
14
|
-
|
15
|
-
def after_save record
|
16
|
-
return unless target
|
17
|
-
|
18
|
-
get_value_from_target record
|
19
|
-
force_update_target record
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|