sqldsl 1.1.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ class ReceiveAny #:nodoc:
2
+ attr_reader :to_sql
3
+
4
+ def initialize(identifier, builder)
5
+ @to_sql = identifier.to_s
6
+ @builder = builder
7
+ end
8
+
9
+ def <=(arg)
10
+ @builder.sql_parts << "#{self.to_sql} <= #{arg.to_sql}"
11
+ end
12
+
13
+ def >=(arg)
14
+ @builder.sql_parts << "#{self.to_sql} >= #{arg.to_sql}"
15
+ end
16
+
17
+ def append_on_setter(lval, rval)
18
+ @builder.equal(lval.to_sym, rval)
19
+ end
20
+
21
+ def method_missing(sym, *args)
22
+ @to_sql << ".#{sym.to_s}".chomp("=")
23
+ append_on_setter(self.to_sql, args.first) if sym.to_s =~ /=$/
24
+ self
25
+ end
26
+ end
data/lib/sqldsl.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require File.dirname(__FILE__) + '/receive_any.rb'
1
2
  require File.dirname(__FILE__) + '/where_value.rb'
2
3
  require File.dirname(__FILE__) + '/object.rb'
3
4
  require File.dirname(__FILE__) + '/symbol.rb'
data/lib/where_builder.rb CHANGED
@@ -58,8 +58,12 @@ class WhereBuilder
58
58
  " where #{sql_parts.join(' and ')}"
59
59
  end
60
60
 
61
- def sql_parts #:nodoc:
61
+ def sql_parts #:nodoc:
62
62
  @sql_parts ||= []
63
63
  end
64
64
 
65
+ def method_missing(sym, *args) #:nodoc:
66
+ ReceiveAny.new(sym, self)
67
+ end
68
+
65
69
  end
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.1.1"
30
+ s.version = "1.2.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'
@@ -44,6 +44,6 @@ specification = Gem::Specification.new do |s|
44
44
  end
45
45
 
46
46
  Rake::GemPackageTask.new(specification) do |package|
47
- package.need_zip = true
48
- package.need_tar = true
47
+ package.need_zip = false
48
+ package.need_tar = false
49
49
  end
@@ -8,7 +8,49 @@ class WhereBuilderTest < Test::Unit::TestCase
8
8
  end
9
9
  assert_equal ' where foo.column1 = bar.column2', statement.to_sql
10
10
  end
11
+
12
+ def test_less_then_equal_where_criteria
13
+ statement = WhereBuilder.new do
14
+ column1 <= column2
15
+ end
16
+ assert_equal " where column1 <= column2", statement.to_sql
17
+ end
18
+
19
+ def test_less_then_equal_with_table_aliasing_where_criteria
20
+ statement = WhereBuilder.new do
21
+ table1.column1 <= table2.column2
22
+ end
23
+ assert_equal " where table1.column1 <= table2.column2", statement.to_sql
24
+ end
25
+
26
+ def test_less_then_equal_with_table_aliasing_where_criteria
27
+ statement = WhereBuilder.new do
28
+ table1.column1 >= table2.column2
29
+ end
30
+ assert_equal " where table1.column1 >= table2.column2", statement.to_sql
31
+ end
11
32
 
33
+ def test_equal_with_table_aliasing_where_criteria
34
+ statement = WhereBuilder.new do
35
+ table1.Column1 = table2.Folumn2
36
+ end
37
+ assert_equal " where table1.Column1 = table2.Folumn2", statement.to_sql
38
+ end
39
+
40
+ def test_equal_with_a_numeric
41
+ statement = WhereBuilder.new do
42
+ table1.Column1 = 1
43
+ end
44
+ assert_equal " where table1.Column1 = 1", statement.to_sql
45
+ end
46
+
47
+ def test_equal_with_a_string
48
+ statement = WhereBuilder.new do
49
+ table1.Column1 = "foo"
50
+ end
51
+ assert_equal " where table1.Column1 = 'foo'", statement.to_sql
52
+ end
53
+
12
54
  def test_single_equal_with_array_where_criteria
13
55
  statement = WhereBuilder.new do
14
56
  equal :'foo.column1', ['foo','bar']
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: sqldsl
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
6
+ version: 1.2.2
7
7
  date: 2007-03-01 00:00:00 -05:00
8
8
  summary: A DSL for creating SQL Statements
9
9
  require_paths:
@@ -36,6 +36,7 @@ files:
36
36
  - lib/insert.rb
37
37
  - lib/numeric.rb
38
38
  - lib/object.rb
39
+ - lib/receive_any.rb
39
40
  - lib/select.rb
40
41
  - lib/sql_statement.rb
41
42
  - lib/sqldsl.rb