adaptive_alias 1.1.0 → 1.1.2

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: 7a49038a810d4dcbbd42effa1664ff3495966c9a097df8939f92632e5fae54ac
4
+ data.tar.gz: 3bee0518e9915af89ac616be205a73da6155e09d9f3d28947cd3cf9145e18660
5
5
  SHA512:
6
- metadata.gz: 2c676366d3132428d290da9291e886f06620d07836a56b87bb59d82f4dc84b86e8ba73f317a26b126d01bb4011a86c04d5653476c277b49d2f81d3728be5e973
7
- data.tar.gz: d26cc5ad6eb77b9cba338788eafcb9f3826b7dbe4cc4afbf1dfd8e22f32bf626be7294bfd87f007e60db429f7294127f994eb4d402c9699cde83017b0b38b540
6
+ metadata.gz: '094892c502fe7343c74a5dae66ab57b1bd21405a73cf38c390c41b12bfd8d01f39c5d9cec78920ca1a388e93be68e280c95041a3fae4d43f9a7ea9ed931f6d22'
7
+ data.tar.gz: 1c7e437b160e7ae6cbb8bb8624f654a220ed35fdbedae3a5a45a306f616bab4f7e62153c08cc874e59a806a7fd5bdc269a86c231180b597b333e9e2556e13acd
@@ -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,5 +1,12 @@
1
1
  ## Change Log
2
2
 
3
+ ### [v1.1.1](https://github.com/khiav223577/adaptive_alias/compare/v1.1.0...v1.1.1) 2022/10/07
4
+ - [#24](https://github.com/khiav223577/adaptive_alias/pull/24) [Fix] Disappeared value when instantiating all and then create / update multiple models one by one (@khiav223577)
5
+ - [#23](https://github.com/khiav223577/adaptive_alias/pull/23) [Enhance] No need to determine missing value manually (@khiav223577)
6
+
7
+ ### [v1.1.0](https://github.com/khiav223577/adaptive_alias/compare/v1.0.0...v1.1.0) 2022/09/27
8
+ - [#22](https://github.com/khiav223577/adaptive_alias/pull/22) [Fix] Creation via autosave(belongs_to) association (@khiav223577)
9
+
3
10
  ### [v1.0.0](https://github.com/khiav223577/adaptive_alias/compare/v0.2.4...v1.0.0) 2022/09/22
4
11
  - [#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
12
  - [#20](https://github.com/khiav223577/adaptive_alias/pull/20) [Fix] Problems with STI classes and models that uses same table name (@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
@@ -0,0 +1,16 @@
1
+ require 'active_record'
2
+
3
+ module AdaptiveAlias
4
+ module Hooks
5
+ module Calculations
6
+ def perform_calculation(*)
7
+ AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ # Nested module include is not supported until ruby 3.0
14
+ class ActiveRecord::Relation
15
+ prepend AdaptiveAlias::Hooks::Calculations
16
+ 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.2'
3
3
  end
@@ -15,6 +15,7 @@ require 'adaptive_alias/hooks/singular_association'
15
15
  require 'adaptive_alias/hooks/relation'
16
16
  require 'adaptive_alias/hooks/active_record_core'
17
17
  require 'adaptive_alias/hooks/active_record_persistence'
18
+ require 'adaptive_alias/hooks/calculations'
18
19
 
19
20
  module AdaptiveAlias
20
21
  @log_interval = 10 * 60
@@ -70,13 +71,5 @@ module AdaptiveAlias
70
71
  klass.prepend(@model_modules[klass])
71
72
  return @model_modules[klass]
72
73
  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
74
  end
82
75
  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.2
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-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - lib/adaptive_alias/hooks/active_record_persistence.rb
133
133
  - lib/adaptive_alias/hooks/association.rb
134
134
  - lib/adaptive_alias/hooks/association_scope.rb
135
+ - lib/adaptive_alias/hooks/calculations.rb
135
136
  - lib/adaptive_alias/hooks/relation.rb
136
137
  - lib/adaptive_alias/hooks/singular_association.rb
137
138
  - lib/adaptive_alias/patches/backward_patch.rb