adaptive_alias 1.2.0 → 1.3.0

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: ea9cff7fa278b8d8a4fcb07a8acb7cca4e9fc11edea3540314c82f8e8f7bd4c4
4
- data.tar.gz: 24e34e5bc93827011bc36414cee5513b7ebda21e980b61e282c053436b8b917f
3
+ metadata.gz: c77a56c9682de40b3f7c0f8a9da86f3fe2e263b9007ce7fc3f629de1e32a1306
4
+ data.tar.gz: 4f1e927143e3eaafdaf4930adad533e5aade02a2bc08ba2d893783cc11427b61
5
5
  SHA512:
6
- metadata.gz: 64fc033de6ab1add5e4bcba89e80bdc4d9c0720856593389ee4802db36890b4a685e153a3629766c5bda34c008ef744283d7b0e8951d82c1240c6863a2fd4edd
7
- data.tar.gz: d01042b8f6871039a1d448794c596ebc86fd1a7df867aa7bb570d61d6be04ed547b82c478b731d9febd6c006d7075cf276b306f023c6ac760f0cf3e50e8d388c
6
+ metadata.gz: 8e4abb047b36b3d433f6b41059ed0d687d39746c87bd272c19ebab3dc99dfc3f4ab21c92a0137cb67b49dd8610d8187226bcb83e4e9ee21dbd0a24356b7559ed
7
+ data.tar.gz: 45865c03b79c4e1e675c70feed424eabd79313e289fcde60397b36fe83c5ae76cd5eb65ef0ef37ea12110972007708edec31ce2f3d0b2cfd3fdb6507b54e9fd1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Change Log
2
2
 
3
+ ### [v1.2.1](https://github.com/khiav223577/adaptive_alias/compare/v1.2.0...v1.2.1) 2022/10/13
4
+ - [#31](https://github.com/khiav223577/adaptive_alias/pull/31) [Fix] Deal with `exists?` (@khiav223577)
5
+ - [#30](https://github.com/khiav223577/adaptive_alias/pull/30) [Test] Add test cases to test raw sql query (@khiav223577)
6
+ - [#29](https://github.com/khiav223577/adaptive_alias/pull/29) [Fix] Rescue queries fired by `update_all` (@khiav223577)
7
+
8
+ ### [v1.2.0](https://github.com/khiav223577/adaptive_alias/compare/v1.1.2...v1.2.0) 2022/10/12
9
+ - [#28](https://github.com/khiav223577/adaptive_alias/pull/28) [Fix] Deal with OR-query (@khiav223577)
10
+ - [#27](https://github.com/khiav223577/adaptive_alias/pull/27) [Enhance] make sure `mark_removable` will be called when manually remove patch (@khiav223577)
11
+ - [#26](https://github.com/khiav223577/adaptive_alias/pull/26) [Fix] Deal with old attribute sets come from cache (identity_cache) (@khiav223577)
12
+
3
13
  ### [v1.1.2](https://github.com/khiav223577/adaptive_alias/compare/v1.1.1...v1.1.2) 2022/10/11
4
14
  - [#25](https://github.com/khiav223577/adaptive_alias/pull/25) [Fix] Deal with count, sum, and group (@khiav223577)
5
15
 
@@ -2,14 +2,14 @@ module AdaptiveAlias
2
2
  module Hooks
3
3
  module ActiveRecordPersistence
4
4
  def _update_record
5
- AdaptiveAlias.rescue_statement_invalid(model: self) do
5
+ AdaptiveAlias.rescue_statement_invalid(model_klass: self.class) do
6
6
  attribute_set_fix!
7
7
  super
8
8
  end
9
9
  end
10
10
 
11
11
  def _create_record(*)
12
- AdaptiveAlias.rescue_statement_invalid(model: self) do
12
+ AdaptiveAlias.rescue_statement_invalid(model_klass: self.class) do
13
13
  attribute_set_fix!
14
14
  super
15
15
  end
@@ -0,0 +1,34 @@
1
+ require 'active_record'
2
+
3
+ module AdaptiveAlias
4
+ module Hooks
5
+ module InsertAll
6
+ def initialize(*, **)
7
+ super
8
+
9
+ adjust_keys_by_attribute_aliases
10
+ end
11
+
12
+ def execute
13
+ AdaptiveAlias.rescue_statement_invalid(model_klass: @model) do
14
+ adjust_keys_by_attribute_aliases
15
+ super
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def adjust_keys_by_attribute_aliases
22
+ if @model.attribute_aliases.keys.any?{|s| @keys.include?(s) }
23
+ @keys = @keys.map{|s| @model.attribute_aliases[s] || s }.to_set
24
+ @inserts = @inserts.map{|insert| insert.transform_keys{|s| @model.attribute_aliases[s.to_s] || s } }
25
+ @keys_including_timestamps = nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ class ActiveRecord::InsertAll
33
+ prepend AdaptiveAlias::Hooks::InsertAll
34
+ end
@@ -5,6 +5,14 @@ module AdaptiveAlias
5
5
  AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
6
6
  end
7
7
 
8
+ def update_all(*)
9
+ AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
10
+ end
11
+
12
+ def exists?(*)
13
+ AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
14
+ end
15
+
8
16
  def select_all(*)
9
17
  AdaptiveAlias.rescue_statement_invalid(relation: self){ super }
10
18
  end
@@ -69,7 +69,7 @@ module AdaptiveAlias
69
69
  end
70
70
  end
71
71
 
72
- @check_matched = proc do |relation, reflection, model, error|
72
+ @check_matched = proc do |relation, reflection, model_klass, error|
73
73
  next false if not patch.removable
74
74
 
75
75
  # Error highlight behavior in Ruby 3.1 pollutes the error message
@@ -79,8 +79,8 @@ module AdaptiveAlias
79
79
  if ambiguous
80
80
  next false if relation and klass.table_name != relation.klass.table_name
81
81
  next false if reflection and klass.table_name != reflection.klass.table_name
82
- next false if model and klass.table_name != model.class.table_name
83
- next false if !relation and !reflection and !model
82
+ next false if model_klass and klass.table_name != model_klass.table_name
83
+ next false if !relation and !reflection and !model_klass
84
84
  end
85
85
 
86
86
  next false if not expected_association_err_msgs.include?(error_msg) and not ambiguous
@@ -1,3 +1,3 @@
1
1
  module AdaptiveAlias
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -14,6 +14,7 @@ require 'adaptive_alias/hooks/relation'
14
14
  require 'adaptive_alias/hooks/active_record_core'
15
15
  require 'adaptive_alias/hooks/active_record_persistence'
16
16
  require 'adaptive_alias/hooks/calculations'
17
+ require 'adaptive_alias/hooks/insert_all'
17
18
 
18
19
  module AdaptiveAlias
19
20
  @log_interval = 10 * 60
@@ -42,14 +43,14 @@ module AdaptiveAlias
42
43
  end
43
44
  end
44
45
 
45
- def rescue_statement_invalid(relation: nil, reflection: nil, model: nil, &block)
46
+ def rescue_statement_invalid(relation: nil, reflection: nil, model_klass: nil, &block)
46
47
  yield
47
48
  rescue ActiveRecord::StatementInvalid => error
48
- _key, patch = AdaptiveAlias.current_patches.find{|_key, patch| patch.check_matched.call(relation, reflection, model, error) }
49
+ _key, patch = AdaptiveAlias.current_patches.find{|_key, patch| patch.check_matched.call(relation, reflection, model_klass, error) }
49
50
  raise error if patch == nil
50
51
 
51
52
  patch.remove_and_fix_association.call(relation, reflection) do
52
- return rescue_statement_invalid(relation: relation, reflection: reflection, model: model, &block)
53
+ return rescue_statement_invalid(relation: relation, reflection: reflection, model_klass: model_klass, &block)
53
54
  end
54
55
  end
55
56
 
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.2.0
4
+ version: 1.3.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-10-12 00:00:00.000000000 Z
11
+ date: 2022-10-20 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/calculations.rb
135
+ - lib/adaptive_alias/hooks/insert_all.rb
135
136
  - lib/adaptive_alias/hooks/relation.rb
136
137
  - lib/adaptive_alias/patches/backward_patch.rb
137
138
  - lib/adaptive_alias/patches/base.rb