bugfixes: ranges, vid===Symbol, And/Or in NotInRange

This commit is contained in:
Denis Knauf 2011-11-28 15:47:48 +01:00
parent 1d6baf41e3
commit 080237c5d7
3 changed files with 18 additions and 6 deletions

2
TODO
View file

@ -1 +1,3 @@
1) gem-plugin 1) gem-plugin
2) deprecated-warnings rails 3.1:
* DEPRECATION WARNING: primary_key_name is deprecated and will be removed from Rails 3.2 (use foreign_key instead).

View file

@ -99,7 +99,7 @@ class SmqlToAR
# Versuche das Objekt zu erkennen. Operator und Expected muessen passen. # Versuche das Objekt zu erkennen. Operator und Expected muessen passen.
# Passt das Object, die Klasse instanzieren. # Passt das Object, die Klasse instanzieren.
def try_parse model, cols, op, val def try_parse model, cols, op, val
#p :self => name, :try_parse => op, :cols => cols, :with => self::Operator, :value => val, :expected => self::Expected, :model => model.name #p :class => self, :self => name, :try_parse => op, :cols => cols, :with => self::Operator, :value => val, :expected => self::Expected, :model => model.name
new model, cols, val if self::Operator === op and self::Expected.any?( &it === val) new model, cols, val if self::Operator === op and self::Expected.any?( &it === val)
end end
@ -109,6 +109,7 @@ class SmqlToAR
end end
def initialize model, cols, val def initialize model, cols, val
#p init: self, caller: caller
@model, @cols = model, cols @model, @cols = model, cols
@value = case val @value = case val
when Hash, Range then val when Hash, Range then val
@ -151,7 +152,7 @@ class SmqlToAR
# #=> ( givenname = 'Peter' OR surname = 'Peter' ) AND ( givenname = 'Mueller' OR surname = 'Mueller' ) # #=> ( givenname = 'Peter' OR surname = 'Peter' ) AND ( givenname = 'Mueller' OR surname = 'Mueller' )
def build builder, table def build builder, table
values = Hash[ @value.collect {|value| [ builder.vid, value ] } ] values = Hash[ @value.collect {|value| [ builder.vid, value ] } ]
values.each {|k, v| builder.wobs k.sym => v } values.each {|k, v| builder.wobs k.to_sym => v }
if 1 == @cols.length if 1 == @cols.length
@cols.each do |col| @cols.each do |col|
col.joins builder, table col.joins builder, table
@ -177,7 +178,7 @@ class SmqlToAR
Where = "%s NOT BETWEEN %s AND %s" Where = "%s NOT BETWEEN %s AND %s"
Expected = [Range, lambda {|val| Array === val && 2 == val.length } ] Expected = [Range, lambda {|val| Array === val && 2 == val.length } ]
def initialze model, cols, val def initialize model, cols, val
if Array === val && 2 == val.length if Array === val && 2 == val.length
f, l = val f, l = val
f, l = Time.parse(f), Time.parse(l) if f.kind_of? String f, l = Time.parse(f), Time.parse(l) if f.kind_of? String
@ -187,7 +188,7 @@ class SmqlToAR
end end
def build builder, table def build builder, table
builder.wobs (v1 = builder.vid) => @value.begin, (v2 = builder.vid) => @value.end builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
@cols.each do |col| @cols.each do |col|
col.joins builder, table col.joins builder, table
builder.where self.class::Where % [ builder.column( table+col.path, col.col), v1, v2] builder.where self.class::Where % [ builder.column( table+col.path, col.col), v1, v2]
@ -242,13 +243,19 @@ class SmqlToAR
end end
def build builder, table def build builder, table
if 2 < @cols.first.second.length
b2, b3 = And, Or
else
b2, b3 = Or, And
end
b2 = b2.new builder
@cols.each do |col, sub| @cols.each do |col, sub|
model, *sub = sub model, *sub = sub
t = table + col.path + [col.col] t = table + col.path + [col.col]
col.joins.each {|j, m| builder.joins table+j, m } col.joins.each {|j, m| builder.joins table+j, m }
builder.joins t, model builder.joins t, model
b2 = 1 == sub.length ? builder : Or.new( builder) b4 = b3.new( b2)
sub.each {|i| i.collect( &it.build( And.new( b2), t)) } sub.each {|i| i.collect( &it.build( And.new( b4), t)) }
end end
self self
end end

View file

@ -26,6 +26,9 @@ class SmqlToAR
def to_sym() "smql_c#{@vid}".to_sym end def to_sym() "smql_c#{@vid}".to_sym end
alias sym to_sym alias sym to_sym
def to_i() @vid end def to_i() @vid end
def === other
to_s === other || to_sym === other || to_i === other || self == other || self === other
end
end end
class Aliases < Hash class Aliases < Hash