2008-02-27 23:50:19 +03:00
|
|
|
class ARCondition
|
|
|
|
attr_reader :conditions
|
|
|
|
|
|
|
|
def initialize(condition=nil)
|
|
|
|
@conditions = ['1=1']
|
2008-03-11 22:33:38 +03:00
|
|
|
add(condition) if condition
|
2008-02-27 23:50:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def add(condition)
|
|
|
|
if condition.is_a?(Array)
|
|
|
|
@conditions.first << " AND (#{condition.first})"
|
|
|
|
@conditions += condition[1..-1]
|
|
|
|
elsif condition.is_a?(String)
|
|
|
|
@conditions.first << " AND (#{condition})"
|
|
|
|
else
|
|
|
|
raise "Unsupported #{condition.class} condition: #{condition}"
|
|
|
|
end
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(condition)
|
|
|
|
add(condition)
|
|
|
|
end
|
|
|
|
end
|