sqldsl 1.4.1 → 1.4.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.
data/README CHANGED
@@ -154,10 +154,9 @@ See the tests for more examples
154
154
  end
155
155
 
156
156
  def test_select_with_inner_join
157
- expected = "select * from t1 a inner join t2 b on a.id = b.id inner join t3 c on b.id2 = c.id where c.attr1 = 'foo' and b.attr1 = 'foo2'"
158
- statement = Select.all.from[:t1.as(:a)].inner_join[:t2.as(:b)].on do
157
+ expected = "select * from t1 a inner join t2 b, t3 c on a.id = b.id and b.id2 = c.id where c.attr1 = 'foo' and b.attr1 = 'foo2'"
158
+ statement = Select.all.from[:t1.as(:a)].inner_join[:t2.as(:b), :t3.as(:c)].on do
159
159
  a.id == b.id
160
- end.inner_join[:t3.as(:c)].on do
161
160
  b.id2 == c.id
162
161
  end.where do
163
162
  c.attr1 == 'foo'
@@ -195,5 +194,6 @@ See the tests for more examples
195
194
  end
196
195
 
197
196
  === Contributors
198
- Matt Deiters[http://www.theagiledeveloper.com]
199
- Sergio Espeja[http://spejman-on-rails.blogspot.com/]
197
+ Matt[http://www.theagiledeveloper.com] Deiters[http://www.theagiledeveloper.com]
198
+
199
+ Sergio[http://spejman-on-rails.blogspot.com/] Espeja[http://spejman-on-rails.blogspot.com/]
@@ -3,7 +3,7 @@ class InnerJoinBuilder #:nodoc:
3
3
  @select_builder = select_builder
4
4
  end
5
5
 
6
- def [](table_name)
7
- @select_builder.inner_join_table(table_name)
6
+ def [](*table_names)
7
+ @select_builder.inner_join_table(table_names)
8
8
  end
9
9
  end
data/lib/select.rb CHANGED
@@ -78,15 +78,18 @@ class Select < SqlStatement
78
78
  InnerJoinBuilder.new(self)
79
79
  end
80
80
 
81
- def inner_join_table(table_name) #:nodoc:
81
+ def inner_join_table(*table_names) #:nodoc:
82
82
  @to_sql << " inner join "
83
- if table_name.to_s =~ / as /
84
- @tables << table_name.to_s.split(/ as /).last.to_sym
85
- @to_sql << table_name.to_s.gsub(/ as /, " ")
86
- else
87
- @tables << table_name
88
- @to_sql << table_name.to_s
89
- end
83
+ table_names.flatten!
84
+ @to_sql += table_names.inject([]) do |result, element|
85
+ if element.to_s =~ / as /
86
+ @tables << element.to_s.split(/ as /).last.to_sym
87
+ result << element.to_s.gsub(/ as /, " ").to_sym
88
+ else
89
+ @tables << element
90
+ result << element
91
+ end
92
+ end.to_sql
90
93
  self
91
94
  end
92
95
 
data/rakefile.rb CHANGED
@@ -27,7 +27,7 @@ Gem::manage_gems
27
27
  specification = Gem::Specification.new do |s|
28
28
  s.name = "sqldsl"
29
29
  s.summary = "A DSL for creating SQL Statements"
30
- s.version = "1.4.1"
30
+ s.version = "1.4.2"
31
31
  s.author = 'Jay Fields'
32
32
  s.description = "A DSL for creating SQL Statements"
33
33
  s.email = 'sqldsl-developer@rubyforge.org'
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/test_helper'
3
3
  class InnerJoinBuilderTest < Test::Unit::TestCase
4
4
  def test_add_tables
5
5
  ij = InnerJoinBuilder.new(s_builder = mock)
6
- s_builder.expects(:inner_join_table).with(:"table1 as foo")
6
+ s_builder.expects(:inner_join_table).with([:"table1 as foo"])
7
7
  ij[:table1.as(:foo)]
8
8
  end
9
9
  end
@@ -77,10 +77,9 @@ class SelectAcceptanceTest < Test::Unit::TestCase
77
77
  end
78
78
 
79
79
  def test_select_with_inner_join
80
- expected = "select * from t1 a inner join t2 b on a.id = b.id inner join t3 c on b.id2 = c.id where c.attr1 = 'foo' and b.attr1 = 'foo2'"
81
- statement = Select.all.from[:t1.as(:a)].inner_join[:t2.as(:b)].on do
80
+ expected = "select * from t1 a inner join t2 b, t3 c on a.id = b.id and b.id2 = c.id where c.attr1 = 'foo' and b.attr1 = 'foo2'"
81
+ statement = Select.all.from[:t1.as(:a)].inner_join[:t2.as(:b), :t3.as(:c)].on do
82
82
  a.id == b.id
83
- end.inner_join[:t3.as(:c)].on do
84
83
  b.id2 == c.id
85
84
  end.where do
86
85
  c.attr1 == 'foo'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: sqldsl
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.1
7
- date: 2007-03-25 00:00:00 -04:00
6
+ version: 1.4.2
7
+ date: 2007-03-26 00:00:00 -04:00
8
8
  summary: A DSL for creating SQL Statements
9
9
  require_paths:
10
10
  - lib