adaptive_alias 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0944e33c0d1dc0b83a734d921c7dadc3f37eaccd2356deebd9775168a98470c
4
- data.tar.gz: 3132d4d8a7de8e5325a8505a79f377daf227322f045e2bdc08ec41443d182348
3
+ metadata.gz: f2c42a4fb70c22a74c09b64fba9c94dc0b1189a94c3e1ca954161ef20e074460
4
+ data.tar.gz: 51ae34971dff012f5e691bd8fd79252db0706277e38dcdf43766b7eca1b163aa
5
5
  SHA512:
6
- metadata.gz: 4cf0abcab7059c77833a1eb3e04672bb26fa8f5d86c5d710d2fb603a0ef12fd07cad2e8acc04eb9e8ae2b8b1b39d09dd1c50382143cd4fcb55d6d5ff648ec6be
7
- data.tar.gz: ba28c61c515149710cffa4a97b23e4870e4b01f2da7e9114034e728e44cefe02a421c839ca1e8667c054660c274f78b0839bf9fd3eee5062b3ea03ff39554b33
6
+ metadata.gz: 1f30e10e5a9b035b255eeb129673563b56b10b5ee2fbdac22717fc31dd9a815e77bc1f5a5238c04dfe9cff27414e6db8e72f8bf5c1e360f3905dff29e1cd17d7
7
+ data.tar.gz: 3b1048bc0d4a42ea9f06a4ecfd215a15ae4687f67d1d52b659a64a096151eb40efe987f7ce3b46273ab89013d0739e7ca925db4ced2f3ca4fe4fcc6a2fb7bb54
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ## Change Log
2
2
 
3
- ### [upcoming](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...HEAD) 2022/08/15
3
+ ### [v0.2.3](https://github.com/khiav223577/adaptive_alias/compare/v0.2.2...v0.2.3) 2022/08/17
4
+ - [#17](https://github.com/khiav223577/adaptive_alias/pull/17) [Feature] Support joins (@khiav223577)
4
5
  - [#16](https://github.com/khiav223577/adaptive_alias/pull/16) [Enhance] No need to clone node (@khiav223577)
5
6
  - [#15](https://github.com/khiav223577/adaptive_alias/pull/15) [Test] Add test cases to test calling pluck on same model (@khiav223577)
6
7
 
@@ -68,6 +68,21 @@ module AdaptiveAlias
68
68
  next true
69
69
  end
70
70
 
71
+ fix_arel_attributes = proc do |attr|
72
+ next if not attr.is_a?(Arel::Attributes::Attribute)
73
+ next if attr.name != current_column.to_s
74
+ next if klass.table_name != attr.relation.name
75
+
76
+ attr.name = alias_column.to_s
77
+ end
78
+
79
+ fix_arel_nodes = proc do |nodes|
80
+ each_nodes(nodes) do |node|
81
+ fix_arel_attributes.call(node.left)
82
+ fix_arel_attributes.call(node.right)
83
+ end
84
+ end
85
+
71
86
  @fix_association = proc do |relation, reflection, error|
72
87
  next false if not patch.removable
73
88
  next false if patch.removed
@@ -84,12 +99,9 @@ module AdaptiveAlias
84
99
  patch.remove!
85
100
 
86
101
  if relation
87
- relation.where_clause.send(:predicates).each do |node|
88
- next if node.left.name != current_column.to_s
89
- next if klass.table_name != node.left.relation.name
90
-
91
- node.left.name = alias_column.to_s
92
- end
102
+ joins = relation.arel.source.right # @ctx.source.right << create_join(relation, nil, klass)
103
+ fix_arel_nodes.call(joins.map{|s| s.right.expr })
104
+ fix_arel_nodes.call(relation.where_clause.send(:predicates))
93
105
  end
94
106
 
95
107
  reflection.clear_association_scope_cache if reflection
@@ -116,6 +128,19 @@ module AdaptiveAlias
116
128
  def mark_removable
117
129
  @removable = true
118
130
  end
131
+
132
+ private
133
+
134
+ def each_nodes(nodes, &block)
135
+ nodes.each do |node|
136
+ case node
137
+ when Arel::Nodes::Equality
138
+ yield(node)
139
+ when Arel::Nodes::And
140
+ each_nodes(node.children, &block)
141
+ end
142
+ end
143
+ end
119
144
  end
120
145
  end
121
146
  end
@@ -1,3 +1,3 @@
1
1
  module AdaptiveAlias
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  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.3
4
+ version: 0.2.4
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-17 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler