comma-heaven 0.5.5 → 0.6.0
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.
@@ -32,14 +32,21 @@ module CommaHeaven
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def table_alias(method = :pluralize)
|
35
|
-
case method
|
36
|
-
when :pluralize
|
37
|
-
|
38
|
-
when :singularize
|
39
|
-
|
35
|
+
return prefix + case method
|
36
|
+
when :pluralize then
|
37
|
+
[((parent && parent.parent) ? parent.table_alias(method) : nil), table, index].compact.join('_')
|
38
|
+
when :singularize then
|
39
|
+
[((parent && parent.parent) ? parent.table_alias(method) : nil), model.name.underscore, index].compact.join('_')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def prefix
|
44
|
+
return case self
|
45
|
+
when HasManyColumns, BelongsToColumns, HasOneColumns then "_"
|
46
|
+
else ''
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
43
50
|
protected
|
44
51
|
def limit
|
45
52
|
(options[:limit] || 1).to_i
|
@@ -8,14 +8,14 @@ describe "BelongsToColumns" do
|
|
8
8
|
|
9
9
|
it "should build correct SQL select clause" do
|
10
10
|
column = CommaHeaven::Sqler::BelongsToColumns.new(@association, {:age => {4 => {:include => '1', :as => ''}}}, 1, @leaf)
|
11
|
-
column.select.should == "
|
11
|
+
column.select.should == "_trees.age AS \"tree_age\""
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should build correct SQL joins clause" do
|
15
15
|
column = CommaHeaven::Sqler::BelongsToColumns.new(@association, {:age => {4 => {:include => '1', :as => ''}}}, 1, @leaf)
|
16
16
|
column.joins.should == <<-EOS.gsub(/\n/, ' ').squeeze(' ').strip
|
17
|
-
LEFT JOIN "trees" AS
|
18
|
-
ON
|
17
|
+
LEFT JOIN "trees" AS _trees
|
18
|
+
ON _trees.id = leafs.tree_id
|
19
19
|
EOS
|
20
20
|
end
|
21
21
|
end
|
data/spec/sqler/columns_spec.rb
CHANGED
@@ -146,23 +146,23 @@ describe "Columns" do
|
|
146
146
|
|
147
147
|
it "should build correct SQL select and joins clauses exporting has many association" do
|
148
148
|
columns = CommaHeaven::Sqler::Columns.new(Tree, {:name => {0 => {:include => '1', :as => ''}}, :age => {1 => {:include => '1', :as => ''}}, :leafs => {2 => {:export => {:position => {4 => {:include => '1', :as => ''}}}, :limit => '3'}}})
|
149
|
-
columns.select.should == 'trees.name AS "tree_name", trees.age AS "tree_age",
|
149
|
+
columns.select.should == 'trees.name AS "tree_name", trees.age AS "tree_age", _leafs_0.position AS "leaf_0_position", _leafs_1.position AS "leaf_1_position", _leafs_2.position AS "leaf_2_position"'
|
150
150
|
columns.joins.should =~ /LEFT JOIN/
|
151
151
|
end
|
152
152
|
|
153
153
|
it "should build correct SQL select and joins clauses exporting belongs to association" do
|
154
154
|
columns = CommaHeaven::Sqler::Columns.new(Tree, {:name => {0 => {:include => '1', :as => ''}}, :age => {1 => {:include => '1', :as => ''}}, :gardener => {2 => {:export => {:surname => {4 => {:include => '1', :as => ''}}}}}})
|
155
|
-
columns.select.should == 'trees.name AS "tree_name", trees.age AS "tree_age",
|
156
|
-
columns.joins.should =~ /\
|
155
|
+
columns.select.should == 'trees.name AS "tree_name", trees.age AS "tree_age", _gardeners.surname AS "gardener_surname"'
|
156
|
+
columns.joins.should =~ /\s_gardeners\s/
|
157
157
|
columns.joins.should =~ /LEFT JOIN/
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should build corrent SQL select and joins clauses for deeper associations" do
|
161
161
|
columns = CommaHeaven::Sqler::Columns.new(Gardener, {:name => {0 => {:include => '1', :as => ''}}, :trees => {1 => {:export => {:name => {0 => {:include => '1', :as => ''}}, :age => {1 => {:include => '1', :as => ''}}, :gardener => {2 => {:export => {:surname => {4 => {:include => '1', :as => ''}}}}}}, :limit => 3}}})
|
162
|
-
columns.select.should == 'gardeners.name AS "gardener_name",
|
162
|
+
columns.select.should == 'gardeners.name AS "gardener_name", _trees_0.name AS "tree_0_name", _trees_0.age AS "tree_0_age", __trees_0_gardeners.surname AS "tree_0_gardener_surname", _trees_1.name AS "tree_1_name", _trees_1.age AS "tree_1_age", __trees_1_gardeners.surname AS "tree_1_gardener_surname", _trees_2.name AS "tree_2_name", _trees_2.age AS "tree_2_age", __trees_2_gardeners.surname AS "tree_2_gardener_surname"'
|
163
163
|
columns.joins.should =~ /LEFT JOIN/
|
164
|
-
columns.joins.should =~ /
|
165
|
-
columns.joins.should =~ /
|
164
|
+
columns.joins.should =~ /_trees/
|
165
|
+
columns.joins.should =~ /_gardeners/
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should build corrent SQL select and joins clauses for deeper and deeper associations" do
|
@@ -187,7 +187,7 @@ describe "Columns" do
|
|
187
187
|
columns.joins.should =~ /trees/
|
188
188
|
columns.joins.should =~ /gardeners/
|
189
189
|
columns.joins.should =~ /leafs/
|
190
|
-
columns.select.should == 'gardeners.name AS "gardener_name",
|
190
|
+
columns.select.should == 'gardeners.name AS "gardener_name", _trees_0.name AS "tree_0_name", _trees_0.age AS "tree_0_age", __trees_0_gardeners.surname AS "tree_0_gardener_surname", __trees_0_leafs_0.position AS "tree_0_leaf_0_position", __trees_0_leafs_1.position AS "tree_0_leaf_1_position", _trees_1.name AS "tree_1_name", _trees_1.age AS "tree_1_age", __trees_1_gardeners.surname AS "tree_1_gardener_surname", __trees_1_leafs_0.position AS "tree_1_leaf_0_position", __trees_1_leafs_1.position AS "tree_1_leaf_1_position", _trees_2.name AS "tree_2_name", _trees_2.age AS "tree_2_age", __trees_2_gardeners.surname AS "tree_2_gardener_surname", __trees_2_leafs_0.position AS "tree_2_leaf_0_position", __trees_2_leafs_1.position AS "tree_2_leaf_1_position"'
|
191
191
|
|
192
192
|
Gardener.scoped(:joins => columns.joins).count.should == 2
|
193
193
|
Gardener.scoped(:joins => columns.joins, :select => columns.select).first.attributes.to_a.length.should == 16
|
@@ -8,20 +8,20 @@ describe "HasManyColumns" do
|
|
8
8
|
|
9
9
|
it "should build correct SQL select clause" do
|
10
10
|
column = CommaHeaven::Sqler::HasManyColumns.new(@association, {:position => {4 => {:include => '1', :as => ''}}}, 1, @tree, 1, :limit => '3')
|
11
|
-
column.select.should == '
|
11
|
+
column.select.should == '_leafs_1.position AS "leaf_1_position"'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should build correct SQL select clause for multiple fields" do
|
15
15
|
column = CommaHeaven::Sqler::HasManyColumns.new(@association, {:position => {4 => {:include => '1', :as => ''}}, :size => {5 => {:include => '1', :as => ''}}}, 1, @tree, 1, :limit => '3')
|
16
|
-
column.select.should == '
|
16
|
+
column.select.should == '_leafs_1.position AS "leaf_1_position", _leafs_1.size AS "leaf_1_size"'
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should build correct SQL joins clause" do
|
20
20
|
column = CommaHeaven::Sqler::HasManyColumns.new(@association, {:position => {4 => {:include => '1', :as => ''}}}, 1, @tree, 1, :limit => '3')
|
21
21
|
column.joins.should == <<-EOS.gsub(/\n/, ' ').squeeze(' ').strip
|
22
|
-
LEFT JOIN "leafs" AS
|
23
|
-
ON trees.id =
|
24
|
-
AND
|
22
|
+
LEFT JOIN "leafs" AS _leafs_1
|
23
|
+
ON trees.id = _leafs_1.tree_id
|
24
|
+
AND _leafs_1.id = (SELECT id FROM "leafs" WHERE tree_id = trees.id LIMIT 1, 1)
|
25
25
|
EOS
|
26
26
|
end
|
27
27
|
end
|
@@ -8,14 +8,14 @@ describe "HasOneColumns" do
|
|
8
8
|
|
9
9
|
it "should build correct SQL select clause" do
|
10
10
|
column = CommaHeaven::Sqler::HasOneColumns.new(@association, {:name => {4 => {:include => '1', :as => ''}}}, 1, @gardener)
|
11
|
-
column.select.should == "
|
11
|
+
column.select.should == "_gardener_clones.name AS \"gardener_clone_name\""
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should build correct SQL joins clause" do
|
15
15
|
column = CommaHeaven::Sqler::HasOneColumns.new(@association, {:name => {4 => {:include => '1', :as => ''}}}, 1, @gardener)
|
16
16
|
column.joins.should == <<-EOS.gsub(/\n/, ' ').squeeze(' ').strip
|
17
|
-
LEFT JOIN "gardener_clones" AS
|
18
|
-
ON gardeners.id =
|
17
|
+
LEFT JOIN "gardener_clones" AS _gardener_clones
|
18
|
+
ON gardeners.id = _gardener_clones.gardener_id
|
19
19
|
EOS
|
20
20
|
end
|
21
21
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comma-heaven
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 5
|
10
|
-
version: 0.5.5
|
4
|
+
prerelease:
|
5
|
+
version: 0.6.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Silvano Stralla
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-05-16 00:00:00 +02:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 2
|
33
|
-
- 9
|
34
24
|
version: 1.2.9
|
35
25
|
type: :development
|
36
26
|
version_requirements: *id001
|
@@ -42,9 +32,6 @@ dependencies:
|
|
42
32
|
requirements:
|
43
33
|
- - ">="
|
44
34
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
35
|
version: "0"
|
49
36
|
type: :runtime
|
50
37
|
version_requirements: *id002
|
@@ -56,26 +43,9 @@ dependencies:
|
|
56
43
|
requirements:
|
57
44
|
- - ">="
|
58
45
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
46
|
version: "0"
|
63
47
|
type: :runtime
|
64
48
|
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: fastercsv
|
67
|
-
prerelease: false
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
77
|
-
type: :runtime
|
78
|
-
version_requirements: *id004
|
79
49
|
description: CommaHeaven permits easy exports of Rails models to CSV
|
80
50
|
email: silvano.stralla@sistrall.it
|
81
51
|
executables: []
|
@@ -121,32 +91,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
91
|
requirements:
|
122
92
|
- - ">="
|
123
93
|
- !ruby/object:Gem::Version
|
124
|
-
hash: 3
|
125
|
-
segments:
|
126
|
-
- 0
|
127
94
|
version: "0"
|
128
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
96
|
none: false
|
130
97
|
requirements:
|
131
98
|
- - ">="
|
132
99
|
- !ruby/object:Gem::Version
|
133
|
-
hash: 3
|
134
|
-
segments:
|
135
|
-
- 0
|
136
100
|
version: "0"
|
137
101
|
requirements: []
|
138
102
|
|
139
103
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.6.1
|
141
105
|
signing_key:
|
142
106
|
specification_version: 3
|
143
107
|
summary: CSV exporter for Rails
|
144
|
-
test_files:
|
145
|
-
|
146
|
-
- spec/export_spec.rb
|
147
|
-
- spec/spec_helper.rb
|
148
|
-
- spec/sqler/belongs_to_association_spec.rb
|
149
|
-
- spec/sqler/column_spec.rb
|
150
|
-
- spec/sqler/columns_spec.rb
|
151
|
-
- spec/sqler/has_many_columns_spec.rb
|
152
|
-
- spec/sqler/has_one_association_spec.rb
|
108
|
+
test_files: []
|
109
|
+
|