lib/persevere_adapter.rb in dm-persevere-adapter-0.51.0 vs lib/persevere_adapter.rb in dm-persevere-adapter-0.52.0
- old
+ new
@@ -1,11 +1,11 @@
require 'rubygems'
require 'dm-core'
require 'dm-aggregates'
require 'dm-types'
require 'extlib'
-require 'json'
+# require 'json'
require 'bigdecimal'
require 'model_json_support'
require 'persevere'
@@ -706,10 +706,19 @@
else
"#{value}=''"
end
end
+ def munge_condition(condition)
+ cond = condition.loaded_value
+
+ cond = "\"#{cond}\"" if cond.is_a?(String)
+ cond = "date(%10.f)" % (Time.parse(cond.to_s).to_f * 1000) if cond.is_a?(DateTime)
+ cond = 'undefined' if cond.nil?
+ return cond
+ end
+
def process_condition(condition)
case condition
# Persevere 1.0 regular expressions are disable for security so we pass them back for DataMapper query filtering
# without regular expressions, the like operator is inordinately challenging hence we pass it back
# when :regexp then "RegExp(\"#{condition.value.source}\").test(#{condition.subject.name})"
@@ -722,15 +731,18 @@
when DataMapper::Query::Conditions::NotOperation then
inside = process_condition(condition.operand)
inside.empty? ? [] : "!(%s)" % inside
when DataMapper::Query::Conditions::InclusionComparison then process_in(condition.subject.name, condition.value)
when DataMapper::Query::Conditions::EqualToComparison then
- cond = condition.loaded_value
-
- cond = "\"#{cond}\"" if cond.is_a?(String)
- cond = "date(%10.f)" % (Time.parse(cond.to_s).to_f * 1000) if cond.is_a?(DateTime)
- cond = 'undefined' if cond.nil?
- "#{condition.subject.field}=#{cond}"
+ "#{condition.subject.field}=#{munge_condition(condition)}"
+ when DataMapper::Query::Conditions::GreaterThanComparison then
+ "#{condition.subject.field}>#{munge_condition(condition)}"
+ when DataMapper::Query::Conditions::LessThanComparison then
+ "#{condition.subject.field}<#{munge_condition(condition)}"
+ when DataMapper::Query::Conditions::GreaterThanOrEqualToComparison then
+ "#{condition.subject.field}>=#{munge_condition(condition)}"
+ when DataMapper::Query::Conditions::LessThanOrEqualToComparison then
+ "#{condition.subject.field}<=#{munge_condition(condition)}"
when DataMapper::Query::Conditions::NullOperation then []
when Array then
old_statement, bind_values = condition
statement = old_statement.dup
bind_values.each{ |bind_value| statement.sub!('?', bind_value.to_s) }
\ No newline at end of file