adaptive_alias 0.0.2 → 0.2.0
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 +70 -70
- data/.gitignore +62 -62
- data/.rubocop.yml +1227 -1227
- data/CHANGELOG.md +12 -1
- data/CODE_OF_CONDUCT.md +49 -49
- data/LICENSE +21 -21
- data/README.md +67 -67
- data/Rakefile +10 -10
- data/adaptive_alias.gemspec +44 -44
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/gemfiles/6.0.gemfile +11 -10
- data/gemfiles/6.1.gemfile +11 -10
- data/gemfiles/7.0.gemfile +12 -11
- data/lib/adaptive_alias/active_model_patches/apply_scope.rb +17 -0
- data/lib/adaptive_alias/active_model_patches/read_attribute.rb +30 -20
- data/lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb +24 -27
- data/lib/adaptive_alias/active_model_patches/write_attribute.rb +25 -0
- data/lib/adaptive_alias/hooks/association.rb +17 -13
- data/lib/adaptive_alias/hooks/association_scope.rb +13 -13
- data/lib/adaptive_alias/hooks/relation.rb +21 -21
- data/lib/adaptive_alias/hooks/singular_association.rb +13 -13
- data/lib/adaptive_alias/patches/backward_patch.rb +24 -21
- data/lib/adaptive_alias/patches/base.rb +110 -75
- data/lib/adaptive_alias/patches/forward_patch.rb +24 -21
- data/lib/adaptive_alias/version.rb +3 -3
- data/lib/adaptive_alias.rb +79 -65
- metadata +8 -6
@@ -1,27 +1,24 @@
|
|
1
|
-
require 'active_model'
|
2
|
-
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module ActiveModelPatches
|
5
|
+
module RemoveAliasAttribute
|
6
|
+
def remove_proxy_call(mod, name)
|
7
|
+
mod.module_eval "remove_method(:'#{name}')", __FILE__, __LINE__ + 1
|
8
|
+
end
|
9
|
+
|
10
|
+
def remove_alias_attribute(new_name)
|
11
|
+
self.attribute_aliases = attribute_aliases.except(new_name.to_s)
|
12
|
+
|
13
|
+
attribute_method_matchers.each do |matcher|
|
14
|
+
matcher_new = matcher.method_name(new_name).to_s
|
15
|
+
remove_proxy_call self, matcher_new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ActiveModel::AttributeMethods::ClassMethods
|
23
|
+
include AdaptiveAlias::ActiveModelPatches::RemoveAliasAttribute
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module ActiveModelPatches
|
5
|
+
module WriteAttribute
|
6
|
+
def write_attribute(attr_name, value)
|
7
|
+
name = attr_name.to_s
|
8
|
+
name = self.class.attribute_aliases[name] || name
|
9
|
+
super(name, value)
|
10
|
+
end
|
11
|
+
|
12
|
+
# This method exists to avoid the expensive primary_key check internally, without
|
13
|
+
# breaking compatibility with the write_attribute API
|
14
|
+
def _write_attribute(attr_name, value) # :nodoc:
|
15
|
+
name = attr_name.to_s
|
16
|
+
name = self.class.attribute_aliases[name] || name
|
17
|
+
super(name, value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module ActiveRecord::AttributeMethods::Write
|
24
|
+
prepend AdaptiveAlias::ActiveModelPatches::WriteAttribute
|
25
|
+
end
|
@@ -1,13 +1,17 @@
|
|
1
|
-
module AdaptiveAlias
|
2
|
-
module Hooks
|
3
|
-
module Association
|
4
|
-
def find_target(*)
|
5
|
-
AdaptiveAlias.rescue_statement_invalid(nil){ super }
|
6
|
-
end
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
1
|
+
module AdaptiveAlias
|
2
|
+
module Hooks
|
3
|
+
module Association
|
4
|
+
def find_target(*)
|
5
|
+
AdaptiveAlias.rescue_statement_invalid(nil, reflection){ super }
|
6
|
+
end
|
7
|
+
|
8
|
+
def create!(attributes = {}, &block)
|
9
|
+
AdaptiveAlias.rescue_statement_invalid(association_scope, reflection){ super }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActiveRecord::Associations::Association
|
16
|
+
prepend AdaptiveAlias::Hooks::Association
|
17
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module AdaptiveAlias
|
2
|
-
module Hooks
|
3
|
-
module AssociationScope
|
4
|
-
def last_chain_scope(
|
5
|
-
AdaptiveAlias.rescue_missing_attribute{ super }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ActiveRecord::Associations::AssociationScope
|
12
|
-
prepend AdaptiveAlias::Hooks::AssociationScope
|
13
|
-
end
|
1
|
+
module AdaptiveAlias
|
2
|
+
module Hooks
|
3
|
+
module AssociationScope
|
4
|
+
def last_chain_scope(_scope, reflection, owner)
|
5
|
+
AdaptiveAlias.rescue_missing_attribute(owner.class){ super }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActiveRecord::Associations::AssociationScope
|
12
|
+
prepend AdaptiveAlias::Hooks::AssociationScope
|
13
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module AdaptiveAlias
|
2
|
-
module Hooks
|
3
|
-
module Relation
|
4
|
-
def pluck(*)
|
5
|
-
AdaptiveAlias.rescue_statement_invalid(self){ super }
|
6
|
-
end
|
7
|
-
|
8
|
-
def select_all(*)
|
9
|
-
AdaptiveAlias.rescue_statement_invalid(self){ super }
|
10
|
-
end
|
11
|
-
|
12
|
-
def exec_queries(*)
|
13
|
-
AdaptiveAlias.rescue_statement_invalid(self){ super }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class ActiveRecord::Relation
|
20
|
-
prepend AdaptiveAlias::Hooks::Relation
|
21
|
-
end
|
1
|
+
module AdaptiveAlias
|
2
|
+
module Hooks
|
3
|
+
module Relation
|
4
|
+
def pluck(*)
|
5
|
+
AdaptiveAlias.rescue_statement_invalid(self, nil){ super }
|
6
|
+
end
|
7
|
+
|
8
|
+
def select_all(*)
|
9
|
+
AdaptiveAlias.rescue_statement_invalid(self, nil){ super }
|
10
|
+
end
|
11
|
+
|
12
|
+
def exec_queries(*)
|
13
|
+
AdaptiveAlias.rescue_statement_invalid(self, nil){ super }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ActiveRecord::Relation
|
20
|
+
prepend AdaptiveAlias::Hooks::Relation
|
21
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
module AdaptiveAlias
|
2
|
-
module Hooks
|
3
|
-
module SingularAssociation
|
4
|
-
def reader(*)
|
5
|
-
AdaptiveAlias.rescue_missing_attribute{ super }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class ActiveRecord::Associations::SingularAssociation
|
12
|
-
prepend AdaptiveAlias::Hooks::SingularAssociation
|
13
|
-
end
|
1
|
+
module AdaptiveAlias
|
2
|
+
module Hooks
|
3
|
+
module SingularAssociation
|
4
|
+
def reader(*)
|
5
|
+
AdaptiveAlias.rescue_missing_attribute(owner.class){ super }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ActiveRecord::Associations::SingularAssociation
|
12
|
+
prepend AdaptiveAlias::Hooks::SingularAssociation
|
13
|
+
end
|
@@ -1,21 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'adaptive_alias/patches/base'
|
4
|
-
|
5
|
-
module AdaptiveAlias
|
6
|
-
module Patches
|
7
|
-
class BackwardPatch < Base
|
8
|
-
def apply!
|
9
|
-
AdaptiveAlias.current_patches[[@klass, @old_column, @new_column]] = self
|
10
|
-
@klass.alias_attribute(@old_column, @new_column)
|
11
|
-
add_hooks!(current_column: @new_column, alias_column: @old_column, log_warning: true)
|
12
|
-
end
|
13
|
-
|
14
|
-
def remove!
|
15
|
-
super
|
16
|
-
@klass.remove_alias_attribute(@old_column)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'adaptive_alias/patches/base'
|
4
|
+
|
5
|
+
module AdaptiveAlias
|
6
|
+
module Patches
|
7
|
+
class BackwardPatch < Base
|
8
|
+
def apply!
|
9
|
+
AdaptiveAlias.current_patches[[@klass, @old_column, @new_column]] = self
|
10
|
+
@klass.alias_attribute(@old_column, @new_column)
|
11
|
+
add_hooks!(current_column: @new_column, alias_column: @old_column, log_warning: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove!
|
15
|
+
super
|
16
|
+
@klass.remove_alias_attribute(@old_column)
|
17
|
+
@klass.define_attribute_method(@old_column)
|
18
|
+
new_patch = ForwardPatch.new(@klass, @old_column, @new_column)
|
19
|
+
new_patch.apply!
|
20
|
+
return new_patch
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,75 +1,110 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AdaptiveAlias
|
4
|
-
module Patches
|
5
|
-
class Base
|
6
|
-
attr_reader :fix_association
|
7
|
-
attr_reader :fix_missing_attribute
|
8
|
-
attr_reader :removed
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
@
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module Patches
|
5
|
+
class Base
|
6
|
+
attr_reader :fix_association
|
7
|
+
attr_reader :fix_missing_attribute
|
8
|
+
attr_reader :removed
|
9
|
+
attr_reader :removable
|
10
|
+
|
11
|
+
def initialize(klass, old_column, new_column)
|
12
|
+
@klass = klass
|
13
|
+
@old_column = old_column
|
14
|
+
@new_column = new_column
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_hooks!(current_column:, alias_column:, log_warning: false)
|
18
|
+
patch = self
|
19
|
+
klass = @klass
|
20
|
+
old_column = @old_column
|
21
|
+
new_column = @new_column
|
22
|
+
|
23
|
+
AdaptiveAlias.get_or_create_model_module(klass).instance_exec do
|
24
|
+
remove_method(new_column) if method_defined?(new_column)
|
25
|
+
define_method(new_column) do
|
26
|
+
AdaptiveAlias.rescue_missing_attribute(klass){ self[new_column] }
|
27
|
+
end
|
28
|
+
|
29
|
+
remove_method("#{new_column}=") if method_defined?("#{new_column}=")
|
30
|
+
define_method("#{new_column}=") do |*args|
|
31
|
+
AdaptiveAlias.rescue_missing_attribute(klass){ super(*args) }
|
32
|
+
end
|
33
|
+
|
34
|
+
remove_method(old_column) if method_defined?(old_column)
|
35
|
+
define_method(old_column) do
|
36
|
+
patch.log_warning if log_warning
|
37
|
+
AdaptiveAlias.rescue_missing_attribute(klass){ self[old_column] }
|
38
|
+
end
|
39
|
+
|
40
|
+
remove_method("#{old_column}=") if method_defined?("#{old_column}=")
|
41
|
+
define_method("#{old_column}=") do |*args|
|
42
|
+
patch.log_warning if log_warning
|
43
|
+
AdaptiveAlias.rescue_missing_attribute(klass){ super(*args) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
expected_association_err_msgs = [
|
48
|
+
"Mysql2::Error: Unknown column '#{klass.table_name}.#{current_column}' in 'where clause'".freeze,
|
49
|
+
"Mysql2::Error: Unknown column '#{current_column}' in 'field list'".freeze,
|
50
|
+
].freeze
|
51
|
+
|
52
|
+
expected_attribute_err_msgs = [
|
53
|
+
"can't write unknown attribute `#{current_column}`".freeze,
|
54
|
+
"missing attribute: #{current_column}".freeze,
|
55
|
+
].freeze
|
56
|
+
|
57
|
+
@fix_missing_attribute = proc do |error_klass, error|
|
58
|
+
next false if not patch.removable
|
59
|
+
next false if patch.removed
|
60
|
+
next false if klass != error_klass
|
61
|
+
next false if not expected_attribute_err_msgs.include?(error.message)
|
62
|
+
|
63
|
+
patch.remove!
|
64
|
+
next true
|
65
|
+
end
|
66
|
+
|
67
|
+
@fix_association = proc do |relation, reflection, error|
|
68
|
+
next false if not patch.removable
|
69
|
+
next false if patch.removed
|
70
|
+
next false if not expected_association_err_msgs.include?(error.message)
|
71
|
+
|
72
|
+
patch.remove!
|
73
|
+
|
74
|
+
if relation
|
75
|
+
relation.where_clause.send(:predicates).each do |node|
|
76
|
+
next if node.left.name != current_column.to_s
|
77
|
+
next if klass.table_name != node.left.relation.name
|
78
|
+
|
79
|
+
node.left = node.left.clone
|
80
|
+
node.left.name = alias_column.to_s
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
reflection.clear_association_scope_cache if reflection
|
85
|
+
|
86
|
+
next true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def log_warning
|
91
|
+
if @prev_warning_time == nil || @prev_warning_time < Time.now - AdaptiveAlias.log_interval
|
92
|
+
@prev_warning_time = Time.now
|
93
|
+
AdaptiveAlias.unexpected_old_column_proc&.call
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def remove!
|
98
|
+
@removed = true
|
99
|
+
@klass.reset_column_information
|
100
|
+
@klass.columns_hash
|
101
|
+
@fix_association = nil
|
102
|
+
@fix_missing_attribute = nil
|
103
|
+
end
|
104
|
+
|
105
|
+
def mark_removable
|
106
|
+
@removable = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -1,21 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'adaptive_alias/patches/base'
|
4
|
-
|
5
|
-
module AdaptiveAlias
|
6
|
-
module Patches
|
7
|
-
class ForwardPatch < Base
|
8
|
-
def apply!
|
9
|
-
AdaptiveAlias.current_patches[[@klass, @old_column, @new_column]] = self
|
10
|
-
@klass.alias_attribute(@new_column, @old_column)
|
11
|
-
add_hooks!(current_column: @old_column, alias_column: @new_column)
|
12
|
-
end
|
13
|
-
|
14
|
-
def remove!
|
15
|
-
super
|
16
|
-
@klass.remove_alias_attribute(@new_column)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'adaptive_alias/patches/base'
|
4
|
+
|
5
|
+
module AdaptiveAlias
|
6
|
+
module Patches
|
7
|
+
class ForwardPatch < Base
|
8
|
+
def apply!
|
9
|
+
AdaptiveAlias.current_patches[[@klass, @old_column, @new_column]] = self
|
10
|
+
@klass.alias_attribute(@new_column, @old_column)
|
11
|
+
add_hooks!(current_column: @old_column, alias_column: @new_column)
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove!
|
15
|
+
super
|
16
|
+
@klass.remove_alias_attribute(@new_column)
|
17
|
+
@klass.define_attribute_method(@new_column)
|
18
|
+
new_patch = BackwardPatch.new(@klass, @old_column, @new_column)
|
19
|
+
new_patch.apply!
|
20
|
+
return new_patch
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module AdaptiveAlias
|
2
|
-
VERSION = '0.0
|
3
|
-
end
|
1
|
+
module AdaptiveAlias
|
2
|
+
VERSION = '0.2.0'
|
3
|
+
end
|
data/lib/adaptive_alias.rb
CHANGED
@@ -1,65 +1,79 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'adaptive_alias/version'
|
4
|
-
require 'adaptive_alias/active_model_patches/read_attribute'
|
5
|
-
require 'adaptive_alias/active_model_patches/
|
6
|
-
require 'adaptive_alias/
|
7
|
-
require 'adaptive_alias/
|
8
|
-
|
9
|
-
require 'adaptive_alias/
|
10
|
-
|
11
|
-
require 'adaptive_alias/hooks/
|
12
|
-
require 'adaptive_alias/hooks/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
attr_accessor :
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def rescue_statement_invalid(relation)
|
44
|
-
yield
|
45
|
-
rescue ActiveRecord::StatementInvalid => error
|
46
|
-
raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_association.call(relation, error) }
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'adaptive_alias/version'
|
4
|
+
require 'adaptive_alias/active_model_patches/read_attribute'
|
5
|
+
require 'adaptive_alias/active_model_patches/write_attribute'
|
6
|
+
require 'adaptive_alias/active_model_patches/remove_alias_attribute'
|
7
|
+
require 'adaptive_alias/active_model_patches/apply_scope'
|
8
|
+
require 'adaptive_alias/patches/backward_patch'
|
9
|
+
require 'adaptive_alias/patches/forward_patch'
|
10
|
+
|
11
|
+
require 'adaptive_alias/hooks/association'
|
12
|
+
require 'adaptive_alias/hooks/association_scope'
|
13
|
+
require 'adaptive_alias/hooks/singular_association'
|
14
|
+
require 'adaptive_alias/hooks/relation'
|
15
|
+
|
16
|
+
module AdaptiveAlias
|
17
|
+
@log_interval = 10 * 60
|
18
|
+
@current_patches = {}
|
19
|
+
@model_modules ||= {}
|
20
|
+
|
21
|
+
class << self
|
22
|
+
attr_accessor :unexpected_old_column_proc
|
23
|
+
attr_accessor :log_interval
|
24
|
+
attr_accessor :current_patches
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def [](old_column, new_column)
|
29
|
+
old_column = old_column.to_sym
|
30
|
+
new_column = new_column.to_sym
|
31
|
+
|
32
|
+
Module.new do
|
33
|
+
extend ActiveSupport::Concern
|
34
|
+
|
35
|
+
included do
|
36
|
+
patch = (column_names.include?(new_column) ? Patches::BackwardPatch : Patches::ForwardPatch).new(self, old_column, new_column)
|
37
|
+
patch.apply!
|
38
|
+
patch.mark_removable
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def rescue_statement_invalid(relation, reflection, &block)
|
44
|
+
yield
|
45
|
+
rescue ActiveRecord::StatementInvalid => error
|
46
|
+
raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_association.call(relation, reflection, error) }
|
47
|
+
|
48
|
+
result = rescue_statement_invalid(relation, reflection, &block)
|
49
|
+
AdaptiveAlias.current_patches.each_value(&:mark_removable)
|
50
|
+
return result
|
51
|
+
end
|
52
|
+
|
53
|
+
def rescue_missing_attribute(klass, &block)
|
54
|
+
yield
|
55
|
+
rescue ActiveModel::MissingAttributeError => error
|
56
|
+
raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_missing_attribute.call(klass, error) }
|
57
|
+
|
58
|
+
result = rescue_missing_attribute(klass, &block)
|
59
|
+
AdaptiveAlias.current_patches.each_value(&:mark_removable)
|
60
|
+
return result
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_or_create_model_module(klass)
|
64
|
+
return @model_modules[klass] if @model_modules[klass]
|
65
|
+
|
66
|
+
@model_modules[klass] = Module.new
|
67
|
+
klass.prepend(@model_modules[klass])
|
68
|
+
return @model_modules[klass]
|
69
|
+
end
|
70
|
+
|
71
|
+
def missing_value?(attributes, klass, name)
|
72
|
+
return false if attributes.key?(name)
|
73
|
+
|
74
|
+
old_name = klass.attribute_aliases.key(name)
|
75
|
+
return false if old_name == nil
|
76
|
+
return !!AdaptiveAlias.current_patches[[klass, old_name.to_sym, name.to_sym]]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|