sqldsl 1.1.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/receive_any.rb +26 -0
- data/lib/sqldsl.rb +1 -0
- data/lib/where_builder.rb +5 -1
- data/rakefile.rb +3 -3
- data/test/where_builder_test.rb +42 -0
- metadata +2 -1
data/lib/receive_any.rb
ADDED
@@ -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
data/lib/where_builder.rb
CHANGED
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.
|
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 =
|
48
|
-
package.need_tar =
|
47
|
+
package.need_zip = false
|
48
|
+
package.need_tar = false
|
49
49
|
end
|
data/test/where_builder_test.rb
CHANGED
@@ -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.
|
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
|