adaptive_alias 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fe3d8361642cc73cba568a7a131efa94f9e17eeada3f1af45990ff876abcb6d
4
- data.tar.gz: befec070dac8af388634e02f5479a78d61ca4e7ddd10e7a489aeae2e2e7180e8
3
+ metadata.gz: 2557ac5e97d02789b75b5468e51f3b67d677195cd90111416222bba40d47b79c
4
+ data.tar.gz: 54561a2436419e0dec856da7d678e3c01dfb437d6642ee3dc5a162492b848a54
5
5
  SHA512:
6
- metadata.gz: 2c676366d3132428d290da9291e886f06620d07836a56b87bb59d82f4dc84b86e8ba73f317a26b126d01bb4011a86c04d5653476c277b49d2f81d3728be5e973
7
- data.tar.gz: d26cc5ad6eb77b9cba338788eafcb9f3826b7dbe4cc4afbf1dfd8e22f32bf626be7294bfd87f007e60db429f7294127f994eb4d402c9699cde83017b0b38b540
6
+ metadata.gz: 68b69b12d2f60509dc9c014d684727f688e57d87cd2baf612ba9cfa4e7efaa7b2e10ec05ecd60d1e83a9c547e4c6f896f816bc529b490ebb8f1a1e76888a5fd1
7
+ data.tar.gz: 90e873a39c890cacea169226ca33a78b404d347aa5a238a793e2a753e61d7b43a46507ea52f50b467ac45fbc923f8135e8b60cd3a4763f1061e20ab94c69aecf
@@ -24,7 +24,7 @@ jobs:
24
24
  ruby:
25
25
  - 2.6
26
26
  - 2.7
27
- - 3.0
27
+ - 3.0.4
28
28
  - 3.1
29
29
  gemfile:
30
30
  - 6.0.gemfile
data/.rubocop.yml CHANGED
@@ -812,7 +812,7 @@ Style/NumericLiterals:
812
812
  Add underscores to large numeric literals to improve their
813
813
  readability.
814
814
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics'
815
- Enabled: true
815
+ Enabled: false
816
816
 
817
817
  Style/OneLineConditional:
818
818
  Description: >-
data/CHANGELOG.md CHANGED
@@ -1,42 +1,45 @@
1
- ## Change Log
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
-
8
- ### [v0.2.4](https://github.com/khiav223577/adaptive_alias/compare/v0.2.3...v0.2.4) 2022/08/18
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)
10
-
11
- ### [v0.2.3](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...v0.2.3) 2022/08/17
12
- - [#17](https://github.com/khiav223577/adaptive_alias/pull/17) [Feature] Support joins (@khiav223577)
13
- - [#16](https://github.com/khiav223577/adaptive_alias/pull/16) [Enhance] No need to clone node (@khiav223577)
14
- - [#15](https://github.com/khiav223577/adaptive_alias/pull/15) [Test] Add test cases to test calling pluck on same model (@khiav223577)
15
-
16
- ### [v0.2.2](https://github.com/khiav223577/adaptive_alias/compare/v0.2.1...v0.2.2) 2022/08/11
17
- - [#14](https://github.com/khiav223577/adaptive_alias/pull/14) [Fix] Fail to use backward-patch when target column has already been migrated (@khiav223577)
18
-
19
- ### [v0.2.1](https://github.com/khiav223577/adaptive_alias/compare/v0.2.0...v0.2.1) 2022/08/11
20
- - [#13](https://github.com/khiav223577/adaptive_alias/pull/13) [Fix] Nested module include is not supported until ruby 3.0 (@khiav223577)
21
- - [#12](https://github.com/khiav223577/adaptive_alias/pull/12) [Test] Add test cases to test column_names (@khiav223577)
22
-
23
- ### [v0.2.0](https://github.com/khiav223577/adaptive_alias/compare/v0.1.0...v0.2.0) 2022/08/05
24
- - [#11](https://github.com/khiav223577/adaptive_alias/pull/11) [Feature] Support polymorphic (@khiav223577)
25
- - [#10](https://github.com/khiav223577/adaptive_alias/pull/10) [Enhance] Prevent adding methods directly in class / module (@khiav223577)
26
- - [#9](https://github.com/khiav223577/adaptive_alias/pull/9) [Enhance] Prevent changing original order of where conditions (@khiav223577)
27
- - [#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)
28
- - [#7](https://github.com/khiav223577/adaptive_alias/pull/7) [Test] Add test cases to test destroy (@khiav223577)
29
-
30
- ### [v0.1.0](https://github.com/khiav223577/adaptive_alias/compare/v0.0.3...v0.1.0) 2022/08/01
31
- - [#6](https://github.com/khiav223577/adaptive_alias/pull/6) [Feature] Deal with creating records (@khiav223577)
32
- - [#5](https://github.com/khiav223577/adaptive_alias/pull/5) [Enhance] Prevent infinite loop if something went wrong (@khiav223577)
33
- - [#4](https://github.com/khiav223577/adaptive_alias/pull/4) [Fix] Attributes writer method should be defined after schema changes (@khiav223577)
34
-
35
- ### [v0.0.3](https://github.com/khiav223577/adaptive_alias/compare/v0.0.2...v0.0.3) 2022/07/27
36
- - [#3](https://github.com/khiav223577/adaptive_alias/pull/3) [Fix] Prevent calling custom column names from raising missing attributes (@khiav223577)
37
-
38
- ### [v0.0.2](https://github.com/khiav223577/adaptive_alias/compare/v0.0.1...v0.0.2) 2022/07/26
39
- - [#2](https://github.com/khiav223577/adaptive_alias/pull/2) [Enhance] Doesn't need rails_compatibility in runtime (@khiav223577)
40
-
41
- ### v0.0.1 2022/07/22
42
- - [#1](https://github.com/khiav223577/adaptive_alias/pull/1) [Feature] Implement adaptive_alias features (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [v1.1.0](https://github.com/khiav223577/adaptive_alias/compare/v1.0.0...v1.1.0) 2022/09/27
4
+ - [#22](https://github.com/khiav223577/adaptive_alias/pull/22) [Fix] creation via autosave(belongs_to) association (@khiav223577)
5
+
6
+ ### [v1.0.0](https://github.com/khiav223577/adaptive_alias/compare/v0.2.4...v1.0.0) 2022/09/22
7
+ - [#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)
8
+ - [#20](https://github.com/khiav223577/adaptive_alias/pull/20) [Fix] Problems with STI classes and models that uses same table name (@khiav223577)
9
+ - [#19](https://github.com/khiav223577/adaptive_alias/pull/19) [Fix] Rescue the error when doing direct access to target table's field (@khiav223577)
10
+
11
+ ### [v0.2.4](https://github.com/khiav223577/adaptive_alias/compare/v0.2.3...v0.2.4) 2022/08/18
12
+ - [#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)
13
+
14
+ ### [v0.2.3](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...v0.2.3) 2022/08/17
15
+ - [#17](https://github.com/khiav223577/adaptive_alias/pull/17) [Feature] Support joins (@khiav223577)
16
+ - [#16](https://github.com/khiav223577/adaptive_alias/pull/16) [Enhance] No need to clone node (@khiav223577)
17
+ - [#15](https://github.com/khiav223577/adaptive_alias/pull/15) [Test] Add test cases to test calling pluck on same model (@khiav223577)
18
+
19
+ ### [v0.2.2](https://github.com/khiav223577/adaptive_alias/compare/v0.2.1...v0.2.2) 2022/08/11
20
+ - [#14](https://github.com/khiav223577/adaptive_alias/pull/14) [Fix] Fail to use backward-patch when target column has already been migrated (@khiav223577)
21
+
22
+ ### [v0.2.1](https://github.com/khiav223577/adaptive_alias/compare/v0.2.0...v0.2.1) 2022/08/11
23
+ - [#13](https://github.com/khiav223577/adaptive_alias/pull/13) [Fix] Nested module include is not supported until ruby 3.0 (@khiav223577)
24
+ - [#12](https://github.com/khiav223577/adaptive_alias/pull/12) [Test] Add test cases to test column_names (@khiav223577)
25
+
26
+ ### [v0.2.0](https://github.com/khiav223577/adaptive_alias/compare/v0.1.0...v0.2.0) 2022/08/05
27
+ - [#11](https://github.com/khiav223577/adaptive_alias/pull/11) [Feature] Support polymorphic (@khiav223577)
28
+ - [#10](https://github.com/khiav223577/adaptive_alias/pull/10) [Enhance] Prevent adding methods directly in class / module (@khiav223577)
29
+ - [#9](https://github.com/khiav223577/adaptive_alias/pull/9) [Enhance] Prevent changing original order of where conditions (@khiav223577)
30
+ - [#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)
31
+ - [#7](https://github.com/khiav223577/adaptive_alias/pull/7) [Test] Add test cases to test destroy (@khiav223577)
32
+
33
+ ### [v0.1.0](https://github.com/khiav223577/adaptive_alias/compare/v0.0.3...v0.1.0) 2022/08/01
34
+ - [#6](https://github.com/khiav223577/adaptive_alias/pull/6) [Feature] Deal with creating records (@khiav223577)
35
+ - [#5](https://github.com/khiav223577/adaptive_alias/pull/5) [Enhance] Prevent infinite loop if something went wrong (@khiav223577)
36
+ - [#4](https://github.com/khiav223577/adaptive_alias/pull/4) [Fix] Attributes writer method should be defined after schema changes (@khiav223577)
37
+
38
+ ### [v0.0.3](https://github.com/khiav223577/adaptive_alias/compare/v0.0.2...v0.0.3) 2022/07/27
39
+ - [#3](https://github.com/khiav223577/adaptive_alias/pull/3) [Fix] Prevent calling custom column names from raising missing attributes (@khiav223577)
40
+
41
+ ### [v0.0.2](https://github.com/khiav223577/adaptive_alias/compare/v0.0.1...v0.0.2) 2022/07/26
42
+ - [#2](https://github.com/khiav223577/adaptive_alias/pull/2) [Enhance] Doesn't need rails_compatibility in runtime (@khiav223577)
43
+
44
+ ### v0.0.1 2022/07/22
45
+ - [#1](https://github.com/khiav223577/adaptive_alias/pull/1) [Feature] Implement adaptive_alias features (@khiav223577)
@@ -18,7 +18,6 @@ module AdaptiveAlias
18
18
  name = self.class.attribute_aliases[name] || name
19
19
 
20
20
  sync_with_transaction_state if @transaction_state&.finalized?
21
- return yield(name) if block_given? and AdaptiveAlias.missing_value?(@attributes, self.class, name)
22
21
  return @attributes.fetch_value(name, &block)
23
22
  end
24
23
  end
@@ -1,8 +1,46 @@
1
1
  module AdaptiveAlias
2
2
  module Hooks
3
3
  module ActiveRecordPersistence
4
+ def _update_record
5
+ AdaptiveAlias.rescue_statement_invalid(model: self) do
6
+ attribute_set_fix!
7
+ super
8
+ end
9
+ end
10
+
4
11
  def _create_record(*)
5
- AdaptiveAlias.rescue_statement_invalid(model: self){ super }
12
+ AdaptiveAlias.rescue_statement_invalid(model: self) do
13
+ attribute_set_fix!
14
+ super
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def attribute_set_fix!
21
+ if attribute_names.any?{|name| self.class.attribute_aliases[name] }
22
+ attributes = @attributes.instance_variable_get(:@attributes)
23
+ attributes = attributes.instance_variable_get(:@delegate_hash) if attributes.is_a?(ActiveModel::LazyAttributeHash)
24
+
25
+ delete_duplicate_keys!(attributes)
26
+
27
+ attributes.transform_keys! do |key|
28
+ self.class.attribute_aliases[key] || key
29
+ end
30
+ end
31
+ end
32
+
33
+ # delete duplicate keys caused by instantiate after migration but before patch removal.
34
+ def delete_duplicate_keys!(attributes)
35
+ duplicate_keys = {}
36
+ delete_keys = []
37
+ attributes.each do |key, _|
38
+ aliased_key = self.class.attribute_aliases[key] || key
39
+ delete_keys << key if duplicate_keys[aliased_key] # delete old key and keep the new one
40
+ duplicate_keys[aliased_key] = true
41
+ end
42
+
43
+ delete_keys.each{|s| attributes.delete(s) }
6
44
  end
7
45
  end
8
46
  end
@@ -63,7 +63,10 @@ module AdaptiveAlias
63
63
  next false if not patch.removable
64
64
  next false if patch.removed
65
65
  next false if klass.table_name != error_klass.table_name
66
- next false if not expected_attribute_err_msgs.include?(error.message)
66
+
67
+ # Error highlight behavior in Ruby 3.1 pollutes the error message
68
+ error_msg = error.respond_to?(:original_message) ? error.original_message : error.message
69
+ next false if not expected_attribute_err_msgs.include?(error_msg)
67
70
 
68
71
  patch.remove!
69
72
  next true
@@ -88,7 +91,9 @@ module AdaptiveAlias
88
91
  next false if not patch.removable
89
92
  next false if patch.removed
90
93
 
91
- ambiguous = expected_ambiguous_association_err_msgs.include?(error.message)
94
+ # Error highlight behavior in Ruby 3.1 pollutes the error message
95
+ error_msg = error.respond_to?(:original_message) ? error.original_message : error.message
96
+ ambiguous = expected_ambiguous_association_err_msgs.include?(error_msg)
92
97
 
93
98
  if ambiguous
94
99
  next false if relation and klass.table_name != relation.klass.table_name
@@ -97,17 +102,10 @@ module AdaptiveAlias
97
102
  next false if !relation and !reflection and !model
98
103
  end
99
104
 
100
- next false if not expected_association_err_msgs.include?(error.message) and not ambiguous
105
+ next false if not expected_association_err_msgs.include?(error_msg) and not ambiguous
101
106
 
102
107
  patch.remove!
103
108
 
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
-
111
109
  if relation
112
110
  relation.reset # reset @arel
113
111
 
@@ -1,3 +1,3 @@
1
1
  module AdaptiveAlias
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -70,13 +70,5 @@ module AdaptiveAlias
70
70
  klass.prepend(@model_modules[klass])
71
71
  return @model_modules[klass]
72
72
  end
73
-
74
- def missing_value?(attributes, klass, name)
75
- return false if attributes.key?(name)
76
-
77
- old_name = klass.attribute_aliases.key(name)
78
- return false if old_name == nil
79
- return !!AdaptiveAlias.current_patches[[klass, old_name.to_sym, name.to_sym]]
80
- end
81
73
  end
82
74
  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.1.0
4
+ version: 1.1.1
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-27 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler