adaptive_alias 1.0.0 → 1.1.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/CHANGELOG.md +6 -1
- data/lib/adaptive_alias/hooks/active_record_core.rb +2 -2
- data/lib/adaptive_alias/hooks/active_record_persistence.rb +14 -0
- data/lib/adaptive_alias/hooks/association.rb +1 -5
- data/lib/adaptive_alias/hooks/relation.rb +3 -3
- data/lib/adaptive_alias/patches/base.rb +10 -1
- data/lib/adaptive_alias/version.rb +1 -1
- data/lib/adaptive_alias.rb +4 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe3d8361642cc73cba568a7a131efa94f9e17eeada3f1af45990ff876abcb6d
|
4
|
+
data.tar.gz: befec070dac8af388634e02f5479a78d61ca4e7ddd10e7a489aeae2e2e7180e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c676366d3132428d290da9291e886f06620d07836a56b87bb59d82f4dc84b86e8ba73f317a26b126d01bb4011a86c04d5653476c277b49d2f81d3728be5e973
|
7
|
+
data.tar.gz: d26cc5ad6eb77b9cba338788eafcb9f3826b7dbe4cc4afbf1dfd8e22f32bf626be7294bfd87f007e60db429f7294127f994eb4d402c9699cde83017b0b38b540
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [v1.0.0](https://github.com/khiav223577/adaptive_alias/compare/v0.2.4...v1.0.0) 2022/09/22
|
4
|
+
- [#21](https://github.com/khiav223577/adaptive_alias/pull/21) [Fix] Model with ignored_columns or calling find_by directly on model class with aliased column argument will fail (@khiav223577)
|
5
|
+
- [#20](https://github.com/khiav223577/adaptive_alias/pull/20) [Fix] Problems with STI classes and models that uses same table name (@khiav223577)
|
6
|
+
- [#19](https://github.com/khiav223577/adaptive_alias/pull/19) [Fix] Rescue the error when doing direct access to target table's field (@khiav223577)
|
7
|
+
|
3
8
|
### [v0.2.4](https://github.com/khiav223577/adaptive_alias/compare/v0.2.3...v0.2.4) 2022/08/18
|
4
|
-
- [#18](https://github.com/khiav223577/adaptive_alias/pull/18) [Fix]
|
9
|
+
- [#18](https://github.com/khiav223577/adaptive_alias/pull/18) [Fix] Get model from a relation with join will not generate right query (after migration) (@khiav223577)
|
5
10
|
|
6
11
|
### [v0.2.3](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...v0.2.3) 2022/08/17
|
7
12
|
- [#17](https://github.com/khiav223577/adaptive_alias/pull/17) [Feature] Support joins (@khiav223577)
|
@@ -2,11 +2,11 @@ module AdaptiveAlias
|
|
2
2
|
module Hooks
|
3
3
|
module ActiveRecordCore
|
4
4
|
def find(*)
|
5
|
-
AdaptiveAlias.rescue_statement_invalid
|
5
|
+
AdaptiveAlias.rescue_statement_invalid{ super }
|
6
6
|
end
|
7
7
|
|
8
8
|
def find_by(*)
|
9
|
-
AdaptiveAlias.rescue_statement_invalid
|
9
|
+
AdaptiveAlias.rescue_statement_invalid{ super }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AdaptiveAlias
|
2
|
+
module Hooks
|
3
|
+
module ActiveRecordPersistence
|
4
|
+
def _create_record(*)
|
5
|
+
AdaptiveAlias.rescue_statement_invalid(model: self){ super }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Nested module include is not supported until ruby 3.0
|
12
|
+
class ActiveRecord::Base
|
13
|
+
prepend AdaptiveAlias::Hooks::ActiveRecordPersistence
|
14
|
+
end
|
@@ -2,11 +2,7 @@ module AdaptiveAlias
|
|
2
2
|
module Hooks
|
3
3
|
module Association
|
4
4
|
def find_target(*)
|
5
|
-
AdaptiveAlias.rescue_statement_invalid(
|
6
|
-
end
|
7
|
-
|
8
|
-
def create!(attributes = {}, &block)
|
9
|
-
AdaptiveAlias.rescue_statement_invalid(association_scope, reflection){ super }
|
5
|
+
AdaptiveAlias.rescue_statement_invalid(reflection: reflection){ super }
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
@@ -2,15 +2,15 @@ module AdaptiveAlias
|
|
2
2
|
module Hooks
|
3
3
|
module Relation
|
4
4
|
def pluck(*)
|
5
|
-
AdaptiveAlias.rescue_statement_invalid(self
|
5
|
+
AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
|
6
6
|
end
|
7
7
|
|
8
8
|
def select_all(*)
|
9
|
-
AdaptiveAlias.rescue_statement_invalid(self
|
9
|
+
AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
|
10
10
|
end
|
11
11
|
|
12
12
|
def exec_queries(*)
|
13
|
-
AdaptiveAlias.rescue_statement_invalid(self
|
13
|
+
AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -84,7 +84,7 @@ module AdaptiveAlias
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
@fix_association = proc do |relation, reflection, error|
|
87
|
+
@fix_association = proc do |relation, reflection, model, error|
|
88
88
|
next false if not patch.removable
|
89
89
|
next false if patch.removed
|
90
90
|
|
@@ -93,12 +93,21 @@ module AdaptiveAlias
|
|
93
93
|
if ambiguous
|
94
94
|
next false if relation and klass.table_name != relation.klass.table_name
|
95
95
|
next false if reflection and klass.table_name != reflection.klass.table_name
|
96
|
+
next false if model and klass.table_name != model.class.table_name
|
97
|
+
next false if !relation and !reflection and !model
|
96
98
|
end
|
97
99
|
|
98
100
|
next false if not expected_association_err_msgs.include?(error.message) and not ambiguous
|
99
101
|
|
100
102
|
patch.remove!
|
101
103
|
|
104
|
+
if model
|
105
|
+
attributes = model.instance_variable_get(:@attributes).instance_variable_get(:@attributes)
|
106
|
+
attributes.transform_keys! do |key|
|
107
|
+
key == current_column.to_s ? alias_column.to_s : key
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
102
111
|
if relation
|
103
112
|
relation.reset # reset @arel
|
104
113
|
|
data/lib/adaptive_alias.rb
CHANGED
@@ -14,6 +14,7 @@ require 'adaptive_alias/hooks/association_scope'
|
|
14
14
|
require 'adaptive_alias/hooks/singular_association'
|
15
15
|
require 'adaptive_alias/hooks/relation'
|
16
16
|
require 'adaptive_alias/hooks/active_record_core'
|
17
|
+
require 'adaptive_alias/hooks/active_record_persistence'
|
17
18
|
|
18
19
|
module AdaptiveAlias
|
19
20
|
@log_interval = 10 * 60
|
@@ -42,12 +43,12 @@ module AdaptiveAlias
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def rescue_statement_invalid(relation, reflection, &block)
|
46
|
+
def rescue_statement_invalid(relation: nil, reflection: nil, model: nil, &block)
|
46
47
|
yield
|
47
48
|
rescue ActiveRecord::StatementInvalid => error
|
48
|
-
raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_association.call(relation, reflection, error) }
|
49
|
+
raise error if AdaptiveAlias.current_patches.all?{|_key, patch| !patch.fix_association.call(relation, reflection, model, error) }
|
49
50
|
|
50
|
-
result = rescue_statement_invalid(relation, reflection, &block)
|
51
|
+
result = rescue_statement_invalid(relation: relation, reflection: reflection, model: model, &block)
|
51
52
|
AdaptiveAlias.current_patches.each_value(&:mark_removable)
|
52
53
|
return result
|
53
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adaptive_alias
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb
|
130
130
|
- lib/adaptive_alias/active_model_patches/write_attribute.rb
|
131
131
|
- lib/adaptive_alias/hooks/active_record_core.rb
|
132
|
+
- lib/adaptive_alias/hooks/active_record_persistence.rb
|
132
133
|
- lib/adaptive_alias/hooks/association.rb
|
133
134
|
- lib/adaptive_alias/hooks/association_scope.rb
|
134
135
|
- lib/adaptive_alias/hooks/relation.rb
|