adaptive_alias 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -6
- data/lib/adaptive_alias/active_model_patches/apply_scope.rb +1 -1
- data/lib/adaptive_alias/active_model_patches/arel_table.rb +26 -0
- data/lib/adaptive_alias/active_model_patches/read_attribute.rb +2 -1
- data/lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb +9 -2
- data/lib/adaptive_alias/active_model_patches/write_attribute.rb +1 -1
- data/lib/adaptive_alias/patches/base.rb +13 -2
- data/lib/adaptive_alias/version.rb +1 -1
- data/lib/adaptive_alias.rb +2 -1
- 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: b0944e33c0d1dc0b83a734d921c7dadc3f37eaccd2356deebd9775168a98470c
|
4
|
+
data.tar.gz: 3132d4d8a7de8e5325a8505a79f377daf227322f045e2bdc08ec41443d182348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf0abcab7059c77833a1eb3e04672bb26fa8f5d86c5d710d2fb603a0ef12fd07cad2e8acc04eb9e8ae2b8b1b39d09dd1c50382143cd4fcb55d6d5ff648ec6be
|
7
|
+
data.tar.gz: ba28c61c515149710cffa4a97b23e4870e4b01f2da7e9114034e728e44cefe02a421c839ca1e8667c054660c274f78b0839bf9fd3eee5062b3ea03ff39554b33
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,33 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [upcoming](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...HEAD) 2022/08/15
|
4
|
+
- [#16](https://github.com/khiav223577/adaptive_alias/pull/16) [Enhance] No need to clone node (@khiav223577)
|
5
|
+
- [#15](https://github.com/khiav223577/adaptive_alias/pull/15) [Test] Add test cases to test calling pluck on same model (@khiav223577)
|
6
|
+
|
7
|
+
### [v0.2.2](https://github.com/khiav223577/adaptive_alias/compare/v0.2.1...v0.2.2) 2022/08/11
|
8
|
+
- [#14](https://github.com/khiav223577/adaptive_alias/pull/14) [Fix] Fail to use backward-patch when target column has already been migrated (@khiav223577)
|
9
|
+
|
10
|
+
### [v0.2.1](https://github.com/khiav223577/adaptive_alias/compare/v0.2.0...v0.2.1) 2022/08/11
|
11
|
+
- [#13](https://github.com/khiav223577/adaptive_alias/pull/13) [Fix] Nested module include is not supported until ruby 3.0 (@khiav223577)
|
12
|
+
- [#12](https://github.com/khiav223577/adaptive_alias/pull/12) [Test] Add test cases to test column_names (@khiav223577)
|
13
|
+
|
14
|
+
### [v0.2.0](https://github.com/khiav223577/adaptive_alias/compare/v0.1.0...v0.2.0) 2022/08/05
|
15
|
+
- [#11](https://github.com/khiav223577/adaptive_alias/pull/11) [Feature] Support polymorphic (@khiav223577)
|
16
|
+
- [#10](https://github.com/khiav223577/adaptive_alias/pull/10) [Enhance] Prevent adding methods directly in class / module (@khiav223577)
|
17
|
+
- [#9](https://github.com/khiav223577/adaptive_alias/pull/9) [Enhance] Prevent changing original order of where conditions (@khiav223577)
|
18
|
+
- [#8](https://github.com/khiav223577/adaptive_alias/pull/8) [Test] Make sure we are reset to use original patch when some test cases fail (@khiav223577)
|
19
|
+
- [#7](https://github.com/khiav223577/adaptive_alias/pull/7) [Test] Add test cases to test destroy (@khiav223577)
|
20
|
+
|
3
21
|
### [v0.1.0](https://github.com/khiav223577/adaptive_alias/compare/v0.0.3...v0.1.0) 2022/08/01
|
4
|
-
- [#6](https://github.com/khiav223577/adaptive_alias/pull/6) Deal with creating records (@khiav223577)
|
5
|
-
- [#5](https://github.com/khiav223577/adaptive_alias/pull/5) Prevent infinite loop if something went wrong (@khiav223577)
|
6
|
-
- [#4](https://github.com/khiav223577/adaptive_alias/pull/4) Fix
|
22
|
+
- [#6](https://github.com/khiav223577/adaptive_alias/pull/6) [Feature] Deal with creating records (@khiav223577)
|
23
|
+
- [#5](https://github.com/khiav223577/adaptive_alias/pull/5) [Enhance] Prevent infinite loop if something went wrong (@khiav223577)
|
24
|
+
- [#4](https://github.com/khiav223577/adaptive_alias/pull/4) [Fix] Attributes writer method should be defined after schema changes (@khiav223577)
|
7
25
|
|
8
26
|
### [v0.0.3](https://github.com/khiav223577/adaptive_alias/compare/v0.0.2...v0.0.3) 2022/07/27
|
9
|
-
- [#3](https://github.com/khiav223577/adaptive_alias/pull/3) Fix
|
27
|
+
- [#3](https://github.com/khiav223577/adaptive_alias/pull/3) [Fix] Prevent calling custom column names from raising missing attributes (@khiav223577)
|
10
28
|
|
11
29
|
### [v0.0.2](https://github.com/khiav223577/adaptive_alias/compare/v0.0.1...v0.0.2) 2022/07/26
|
12
|
-
- [#2](https://github.com/khiav223577/adaptive_alias/pull/2) Doesn't need rails_compatibility in runtime (@khiav223577)
|
30
|
+
- [#2](https://github.com/khiav223577/adaptive_alias/pull/2) [Enhance] Doesn't need rails_compatibility in runtime (@khiav223577)
|
13
31
|
|
14
32
|
### v0.0.1 2022/07/22
|
15
|
-
- [#1](https://github.com/khiav223577/adaptive_alias/pull/1) Implement adaptive_alias features (@khiav223577)
|
33
|
+
- [#1](https://github.com/khiav223577/adaptive_alias/pull/1) [Feature] Implement adaptive_alias features (@khiav223577)
|
@@ -4,7 +4,7 @@ module AdaptiveAlias
|
|
4
4
|
module ActiveModelPatches
|
5
5
|
module ApplyScope
|
6
6
|
def apply_scope(scope, table, key, value)
|
7
|
-
klass = table.instance_variable_get(:@klass) || table.
|
7
|
+
klass = table.instance_variable_get(:@klass) || table.klass
|
8
8
|
key = klass.attribute_aliases[key] || key
|
9
9
|
super(scope, table, key, value)
|
10
10
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module ActiveModelPatches
|
5
|
+
module ArelTable
|
6
|
+
def [](name)
|
7
|
+
name = name.to_s if name.is_a?(Symbol)
|
8
|
+
klass = self.klass
|
9
|
+
name = klass.attribute_aliases[name] || name if klass
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def klass
|
14
|
+
return @type_caster.instance_variable_get(:@klass) if @type_caster.is_a?(ActiveRecord::TypeCaster::Connection)
|
15
|
+
return @type_caster.send(:types) if @type_caster.is_a?(ActiveRecord::TypeCaster::Map)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# https://github.com/rails/rails/commit/1ac40f16c5bc5246a4aaeab0558eb1c3078b3c6e
|
22
|
+
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('6.1')
|
23
|
+
class Arel::Table
|
24
|
+
prepend AdaptiveAlias::ActiveModelPatches::ArelTable
|
25
|
+
end
|
26
|
+
end
|
@@ -19,6 +19,13 @@ module AdaptiveAlias
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
module
|
23
|
-
|
22
|
+
# Nested module include is not supported until ruby 3.0
|
23
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
|
24
|
+
AdaptiveAlias::ActiveModelPatches::RemoveAliasAttribute.instance_methods.each do |method|
|
25
|
+
ActiveModel::AttributeMethods::ClassMethods.define_method(method, AdaptiveAlias::ActiveModelPatches::RemoveAliasAttribute.instance_method(method))
|
26
|
+
end
|
27
|
+
else
|
28
|
+
module ActiveModel::AttributeMethods::ClassMethods
|
29
|
+
include AdaptiveAlias::ActiveModelPatches::RemoveAliasAttribute
|
30
|
+
end
|
24
31
|
end
|
@@ -46,6 +46,10 @@ module AdaptiveAlias
|
|
46
46
|
|
47
47
|
expected_association_err_msgs = [
|
48
48
|
"Mysql2::Error: Unknown column '#{klass.table_name}.#{current_column}' in 'where clause'".freeze,
|
49
|
+
"Mysql2::Error: Unknown column '#{klass.table_name}.#{current_column}' in 'on clause'".freeze,
|
50
|
+
].freeze
|
51
|
+
|
52
|
+
expected_ambiguous_association_err_msgs = [
|
49
53
|
"Mysql2::Error: Unknown column '#{current_column}' in 'field list'".freeze,
|
50
54
|
].freeze
|
51
55
|
|
@@ -67,7 +71,15 @@ module AdaptiveAlias
|
|
67
71
|
@fix_association = proc do |relation, reflection, error|
|
68
72
|
next false if not patch.removable
|
69
73
|
next false if patch.removed
|
70
|
-
|
74
|
+
|
75
|
+
ambiguous = expected_ambiguous_association_err_msgs.include?(error.message)
|
76
|
+
|
77
|
+
if ambiguous
|
78
|
+
next false if relation and klass != relation.klass
|
79
|
+
next false if reflection and klass != reflection.klass
|
80
|
+
end
|
81
|
+
|
82
|
+
next false if not expected_association_err_msgs.include?(error.message) and not ambiguous
|
71
83
|
|
72
84
|
patch.remove!
|
73
85
|
|
@@ -76,7 +88,6 @@ module AdaptiveAlias
|
|
76
88
|
next if node.left.name != current_column.to_s
|
77
89
|
next if klass.table_name != node.left.relation.name
|
78
90
|
|
79
|
-
node.left = node.left.clone
|
80
91
|
node.left.name = alias_column.to_s
|
81
92
|
end
|
82
93
|
end
|
data/lib/adaptive_alias.rb
CHANGED
@@ -5,6 +5,7 @@ require 'adaptive_alias/active_model_patches/read_attribute'
|
|
5
5
|
require 'adaptive_alias/active_model_patches/write_attribute'
|
6
6
|
require 'adaptive_alias/active_model_patches/remove_alias_attribute'
|
7
7
|
require 'adaptive_alias/active_model_patches/apply_scope'
|
8
|
+
require 'adaptive_alias/active_model_patches/arel_table'
|
8
9
|
require 'adaptive_alias/patches/backward_patch'
|
9
10
|
require 'adaptive_alias/patches/forward_patch'
|
10
11
|
|
@@ -33,7 +34,7 @@ module AdaptiveAlias
|
|
33
34
|
extend ActiveSupport::Concern
|
34
35
|
|
35
36
|
included do
|
36
|
-
patch = (column_names.include?(new_column) ? Patches::BackwardPatch : Patches::ForwardPatch).new(self, old_column, new_column)
|
37
|
+
patch = (column_names.include?(new_column.to_s) ? Patches::BackwardPatch : Patches::ForwardPatch).new(self, old_column, new_column)
|
37
38
|
patch.apply!
|
38
39
|
patch.mark_removable
|
39
40
|
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: 0.2.
|
4
|
+
version: 0.2.3
|
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-08-
|
11
|
+
date: 2022-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- gemfiles/7.0.gemfile
|
125
125
|
- lib/adaptive_alias.rb
|
126
126
|
- lib/adaptive_alias/active_model_patches/apply_scope.rb
|
127
|
+
- lib/adaptive_alias/active_model_patches/arel_table.rb
|
127
128
|
- lib/adaptive_alias/active_model_patches/read_attribute.rb
|
128
129
|
- lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb
|
129
130
|
- lib/adaptive_alias/active_model_patches/write_attribute.rb
|