from_clause_translate 0.2.1 → 0.2.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6047a9893a48d5c6dd9de7a79a54626a24ff68ee3dc45839de7af7c726408e55
|
4
|
+
data.tar.gz: f18f6a36db802341261bd87ea818c1e87cf2baa237ecc8c42f67ee5c95af3302
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73ceb06c2144d06142da1b537a2e7762174801488685e53ba900bfa27b78395cedf6c509ec6d151b82b96097d85e476a20ff66fd22021df55b9d0cd7942bd759
|
7
|
+
data.tar.gz: 7ca67fdbdb2362ce6375ebe762aaa490abdf9e5c1762ef524ba8d02d6c7260afac19dedb1c9cd200427203a9acd86e8e5bd0c2e1a3f24ef276a8c927d7b68d33
|
@@ -24,7 +24,7 @@ module ActiveRecord::Relation::Extended
|
|
24
24
|
|
25
25
|
@arel ||= build_arel nil
|
26
26
|
|
27
|
-
columns =
|
27
|
+
columns = translated_columns_build
|
28
28
|
return unless columns
|
29
29
|
|
30
30
|
if @values[:joins]
|
@@ -40,14 +40,15 @@ module ActiveRecord::Relation::Extended
|
|
40
40
|
@arel.from("(#{from}) #{as}")
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def translated_columns_build
|
44
44
|
FromClauseTranslate::TranslatedColumnsBuilder.new(
|
45
|
-
self, @without_projections
|
45
|
+
self, @klass, @without_projections
|
46
46
|
).perform
|
47
47
|
end
|
48
48
|
|
49
49
|
def perform_calculation operation, column_name
|
50
50
|
return super operation, column_name if @without_projections
|
51
|
+
|
51
52
|
rel = spawn
|
52
53
|
rel.instance_variable_set(:@without_projections, true)
|
53
54
|
rel.add_translated_column column_name
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class FromClauseTranslate::TranslatedColumnsBuilder
|
2
|
-
def initialize relation, without_projections
|
2
|
+
def initialize relation, klass, without_projections
|
3
3
|
@relation = relation
|
4
|
-
@klass =
|
4
|
+
@klass = klass
|
5
5
|
@arel = relation.arel
|
6
6
|
@without_projections = without_projections
|
7
7
|
@columns = []
|
@@ -9,10 +9,11 @@ class FromClauseTranslate::TranslatedColumnsBuilder
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def perform
|
12
|
+
@skip_translated = []
|
12
13
|
add_translated_columns_from_values
|
13
14
|
add_translated_columns_from_projections
|
14
15
|
add_translated_columns_from_cores
|
15
|
-
|
16
|
+
add_translated_columns_from_orders
|
16
17
|
|
17
18
|
@columns if @has_translated
|
18
19
|
end
|
@@ -23,10 +24,11 @@ class FromClauseTranslate::TranslatedColumnsBuilder
|
|
23
24
|
translated = @relation.instance_variable_get(:@values)[:translated]
|
24
25
|
return unless translated
|
25
26
|
|
27
|
+
@has_translated = true
|
26
28
|
translated.each do |column|
|
27
29
|
if column.is_a? Hash
|
28
|
-
@has_translated = true
|
29
30
|
column.each do |key, value|
|
31
|
+
@skip_translated << key.to_s
|
30
32
|
@columns << "#{value} AS #{key}"
|
31
33
|
end
|
32
34
|
elsif (selection = translated_selection(column))
|
@@ -51,6 +53,8 @@ class FromClauseTranslate::TranslatedColumnsBuilder
|
|
51
53
|
column = column.to_s
|
52
54
|
|
53
55
|
name = column.first == '"' ? column[1...-1] : column
|
56
|
+
return if @skip_translated.include? name
|
57
|
+
|
54
58
|
selection = translated_selection name
|
55
59
|
return column unless selection
|
56
60
|
|
@@ -88,7 +92,7 @@ class FromClauseTranslate::TranslatedColumnsBuilder
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
|
-
def
|
95
|
+
def add_translated_columns_from_orders
|
92
96
|
@arel.ast.orders.each do |name|
|
93
97
|
name = name.respond_to?(:expr) ? name.expr.name : name.to_sym
|
94
98
|
selection = translated_selection name
|