sqldsl 1.4.2 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ class JoinBuilder #:nodoc:
2
+ def initialize(select_builder, join_type)
3
+ @select_builder = select_builder
4
+ @join_type = join_type
5
+ end
6
+
7
+ def [](*table_names)
8
+ @select_builder.join_table(@join_type, table_names)
9
+ end
10
+ end
data/lib/select.rb CHANGED
@@ -68,18 +68,39 @@ class Select < SqlStatement
68
68
  self
69
69
  end
70
70
 
71
- # call-seq: select.inner_join -> an_inner_join_builder
71
+ # call-seq: select.inner_join -> a_join_builder
72
72
  #
73
- # Returns an InnerJoinBuilder instance.
73
+ # Returns a JoinBuilder instance.
74
74
  #
75
75
  # Select.all.from[:table1].inner_join
76
- # #=> #<InnerJoinBuilder:0x654f4 @select_builder=#<Select:0x65968 @tables=[:table1], @to_sql="select * from table1">>
76
+ # #=> #<JoinBuilder:0x654f4 @select_builder=#<Select:0x65968 @tables=[:table1], @to_sql="select * from table1">>
77
77
  def inner_join
78
- InnerJoinBuilder.new(self)
78
+ JoinBuilder.new(self, "inner")
79
79
  end
80
80
 
81
- def inner_join_table(*table_names) #:nodoc:
82
- @to_sql << " inner join "
81
+ # call-seq: select.left_join -> a_join_builder
82
+ #
83
+ # Returns a JoinBuilder instance.
84
+ #
85
+ # Select.all.from[:table1].left_join
86
+ # #=> #<JoinBuilder:0x654f4 @select_builder=#<Select:0x65968 @tables=[:table1], @to_sql="select * from table1">>
87
+ def left_join
88
+ JoinBuilder.new(self, "left")
89
+ end
90
+
91
+ # call-seq: select.right_join -> a_join_builder
92
+ #
93
+ # Returns a JoinBuilder instance.
94
+ #
95
+ # Select.all.from[:table1].right_join
96
+ # #=> #<JoinBuilder:0x654f4 @select_builder=#<Select:0x65968 @tables=[:table1], @to_sql="select * from table1">>
97
+ def right_join
98
+ JoinBuilder.new(self, "right")
99
+ end
100
+
101
+ def join_table(join_type, table_names) #:nodoc:
102
+
103
+ @to_sql << " #{join_type} join "
83
104
  table_names.flatten!
84
105
  @to_sql += table_names.inject([]) do |result, element|
85
106
  if element.to_s =~ / as /
@@ -92,7 +113,6 @@ class Select < SqlStatement
92
113
  end.to_sql
93
114
  self
94
115
  end
95
-
96
116
  # call-seq: sql_statement.on { block } -> a_sql_statement
97
117
  #
98
118
  # Creates a new OnWhereBuilder instance, passing the block as a parameter, then executes to_sql on the OnWhereBuilder instance.
data/lib/sqldsl.rb CHANGED
@@ -6,7 +6,7 @@ require File.dirname(__FILE__) + '/string.rb'
6
6
  require File.dirname(__FILE__) + '/numeric.rb'
7
7
  require File.dirname(__FILE__) + '/time.rb'
8
8
  require File.dirname(__FILE__) + '/sql_statement.rb'
9
- require File.dirname(__FILE__) + '/inner_join_builder.rb'
9
+ require File.dirname(__FILE__) + '/join_builder.rb'
10
10
  require File.dirname(__FILE__) + '/where_builder.rb'
11
11
  require File.dirname(__FILE__) + '/and_where_builder.rb'
12
12
  require File.dirname(__FILE__) + '/or_where_builder.rb'
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.2"
30
+ s.version = "1.4.4"
31
31
  s.author = 'Jay Fields'
32
32
  s.description = "A DSL for creating SQL Statements"
33
33
  s.email = 'sqldsl-developer@rubyforge.org'
@@ -1,9 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class InnerJoinBuilderTest < Test::Unit::TestCase
3
+ class JoinBuilderTest < Test::Unit::TestCase
4
4
  def test_add_tables
5
- ij = InnerJoinBuilder.new(s_builder = mock)
6
- s_builder.expects(:inner_join_table).with([:"table1 as foo"])
5
+ ij = JoinBuilder.new(s_builder = mock, "inner")
6
+ s_builder.expects(:join_table).with("inner", [:"table1 as foo"])
7
7
  ij[:table1.as(:foo)]
8
8
  end
9
9
  end
data/test/select_test.rb CHANGED
@@ -58,10 +58,14 @@ class SelectTest < Test::Unit::TestCase
58
58
  assert_equal [:table1, :table2], Select.all.from[:table1, :table2].instance_variable_get("@tables")
59
59
  end
60
60
 
61
- def test_inner_join
62
- assert_equal InnerJoinBuilder, Select.all.inner_join.class
61
+ def test_left_join_with_table
62
+ assert_equal "select * from table1 left join table2", Select.all.from[:table1].left_join[:table2].to_sql
63
63
  end
64
-
64
+
65
+ def test_right_join_with_table
66
+ assert_equal "select * from table1 right join table2", Select.all.from[:table1].right_join[:table2].to_sql
67
+ end
68
+
65
69
  def test_inner_join_with_table
66
70
  assert_equal "select * from table1 inner join table2", Select.all.from[:table1].inner_join[:table2].to_sql
67
71
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: sqldsl
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.2
7
- date: 2007-03-26 00:00:00 -04:00
6
+ version: 1.4.4
7
+ date: 2007-05-25 00:00:00 -04:00
8
8
  summary: A DSL for creating SQL Statements
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Jay Fields
30
31
  files:
@@ -33,8 +34,8 @@ files:
33
34
  - lib/blank_slate.rb
34
35
  - lib/delete.rb
35
36
  - lib/distinct_select.rb
36
- - lib/inner_join_builder.rb
37
37
  - lib/insert.rb
38
+ - lib/join_builder.rb
38
39
  - lib/numeric.rb
39
40
  - lib/on_where_builder.rb
40
41
  - lib/or_where_builder.rb
@@ -1,9 +0,0 @@
1
- class InnerJoinBuilder #:nodoc:
2
- def initialize(select_builder)
3
- @select_builder = select_builder
4
- end
5
-
6
- def [](*table_names)
7
- @select_builder.inner_join_table(table_names)
8
- end
9
- end