momomoto 0.1.11 → 0.1.12
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/lib/momomoto/base.rb +16 -11
- data/test/test_base.rb +6 -4
- metadata +2 -2
data/lib/momomoto/base.rb
CHANGED
@@ -87,17 +87,22 @@ module Momomoto
|
|
87
87
|
|
88
88
|
def compile_expression( conditions, operator )
|
89
89
|
where = []
|
90
|
-
conditions
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
90
|
+
case conditions
|
91
|
+
when Array then
|
92
|
+
conditions.each do | value |
|
93
|
+
where << compile_expression( value, operator )
|
94
|
+
end
|
95
|
+
when Hash then
|
96
|
+
conditions.each do | key , value |
|
97
|
+
key = key.to_sym if key.kind_of?( String )
|
98
|
+
case key
|
99
|
+
when :OR then where << "(" + compile_expression( value, "OR" ) + ")"
|
100
|
+
when :AND then where << "(" + compile_expression( value, "AND" ) + ")"
|
101
|
+
else
|
102
|
+
raise CriticalError, "condition key '#{key}' not a column in table '#{table_name}'" unless columns.keys.member?( key )
|
103
|
+
where << columns[key].compile_rule( key, value )
|
104
|
+
end
|
105
|
+
end
|
101
106
|
end
|
102
107
|
where.join( " #{operator} ")
|
103
108
|
end
|
data/test/test_base.rb
CHANGED
@@ -32,10 +32,12 @@ class TestBase < Test::Unit::TestCase
|
|
32
32
|
assert_equal( " WHERE first_name = E'1'" , t.instance_eval do compile_where( :first_name => '1' ) end )
|
33
33
|
assert_equal( " WHERE first_name = E'chu''nky'" , t.instance_eval do compile_where( :first_name => "chu'nky" ) end )
|
34
34
|
assert_equal( " WHERE first_name IN (E'chu''nky',E'bac''n')" , t.instance_eval do compile_where( :first_name => ["chu'nky","bac'n"] ) end )
|
35
|
-
assert_equal( " WHERE person_id = '1'" , t.instance_eval do compile_where( :OR => { :person_id => '1' } ) end )
|
36
|
-
assert_equal( " WHERE person_id = '1'" , t.instance_eval do compile_where( :AND => { :person_id => '1' } ) end )
|
37
|
-
assert_equal( " WHERE person_id = '1' OR first_name = E's'" , t.instance_eval do compile_where( :OR => { :person_id => '1',:first_name=>'s' } ) end )
|
38
|
-
assert_equal( " WHERE person_id = '1' AND first_name = E's'" , t.instance_eval do compile_where( :AND => { :person_id => '1',:first_name=>'s' } ) end )
|
35
|
+
assert_equal( " WHERE (person_id = '1')" , t.instance_eval do compile_where( :OR => { :person_id => '1' } ) end )
|
36
|
+
assert_equal( " WHERE (person_id = '1')" , t.instance_eval do compile_where( :AND => { :person_id => '1' } ) end )
|
37
|
+
assert_equal( " WHERE (person_id = '1' OR first_name = E's')" , t.instance_eval do compile_where( :OR => { :person_id => '1',:first_name=>'s' } ) end )
|
38
|
+
assert_equal( " WHERE (person_id = '1' AND first_name = E's')" , t.instance_eval do compile_where( :AND => { :person_id => '1',:first_name=>'s' } ) end )
|
39
|
+
assert_equal( " WHERE (person_id = '1' AND person_id = '2')" , t.instance_eval do compile_where( :AND =>[{:person_id=>1},{:person_id=>2}] ) end )
|
40
|
+
assert_equal( " WHERE (person_id = '1' OR person_id = '2')" , t.instance_eval do compile_where( :OR =>[{:person_id=>1},{:person_id=>2}] ) end )
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: momomoto
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 0.1.12
|
7
|
+
date: 2007-11-17 00:00:00 +01:00
|
8
8
|
summary: Momomoto is an object relational mapper for PostgreSQL.
|
9
9
|
require_paths:
|
10
10
|
- lib
|