adaptive_alias 1.2.1 → 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: 6ac3bfeadde0c8fed89cc4c1803939cfcb5ebbd8f33bb9ecff1401fa0f33393c
4
- data.tar.gz: e716802e6b36217f0bb94f056183887812f7c488a310d6b7b38e206a2d29e471
3
+ metadata.gz: c77a56c9682de40b3f7c0f8a9da86f3fe2e263b9007ce7fc3f629de1e32a1306
4
+ data.tar.gz: 4f1e927143e3eaafdaf4930adad533e5aade02a2bc08ba2d893783cc11427b61
5
5
  SHA512:
6
- metadata.gz: 14726e4300d86f5f5093c6682d8f8be1f864f7fd29cd4f0978567025fb442f04c4276d3f1e61e8ca90f89429dd6c998fec194e92586f362f56da1c1241d166d2
7
- data.tar.gz: c0b89da78c766cbaf1208b17f2858d35c1b04b972cf13822fd88b6fa9b3b72ad8b28f628cf4fbcfab28290e0fa95df02c03d71510e5acbf6ba77f89c77557208
6
+ metadata.gz: 8e4abb047b36b3d433f6b41059ed0d687d39746c87bd272c19ebab3dc99dfc3f4ab21c92a0137cb67b49dd8610d8187226bcb83e4e9ee21dbd0a24356b7559ed
7
+ data.tar.gz: 45865c03b79c4e1e675c70feed424eabd79313e289fcde60397b36fe83c5ae76cd5eb65ef0ef37ea12110972007708edec31ce2f3d0b2cfd3fdb6507b54e9fd1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ### [v1.2.0](https://github.com/khiav223577/adaptive_alias/compare/v1.1.2...v1.2.0) 2022/10/12
4
9
  - [#28](https://github.com/khiav223577/adaptive_alias/pull/28) [Fix] Deal with OR-query (@khiav223577)
5
10
  - [#27](https://github.com/khiav223577/adaptive_alias/pull/27) [Enhance] make sure `mark_removable` will be called when manually remove patch (@khiav223577)
@@ -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
@@ -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.1'
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.1
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-13 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