Commit 63aafb98 by liyijie

feat: 增加trans_value,支持特殊值

parent 6b7e5cd3
...@@ -20,7 +20,7 @@ module RansackMongo ...@@ -20,7 +20,7 @@ module RansackMongo
or_query(db_adapter, attr, value, p) or_query(db_adapter, attr, value, p)
else else
# attr => name # attr => name
db_adapter.send("#{p}_matcher", attr, value) db_adapter.send("#{p}_matcher", attr, trans_value(value))
end end
rescue NoMethodError => e rescue NoMethodError => e
raise MatcherNotFound, "The matcher #{p} `#{p}_matcher` was not found in the #{db_adapter_class.name}. Check `#{db_adapter_class}.predicates`" raise MatcherNotFound, "The matcher #{p} `#{p}_matcher` was not found in the #{db_adapter_class.name}. Check `#{db_adapter_class}.predicates`"
...@@ -44,10 +44,23 @@ module RansackMongo ...@@ -44,10 +44,23 @@ module RansackMongo
def or_query(db_adapter, attr, value, p) def or_query(db_adapter, attr, value, p)
db_adapter.or_op do db_adapter.or_op do
attr.split('_or_').each do |or_attr| attr.split('_or_').each do |or_attr|
db_adapter.send("#{p}_matcher", or_attr, value) db_adapter.send("#{p}_matcher", or_attr, trans_value(value))
end end
end end
end end
def trans_value value
case value
when 'true'
true
when 'false'
false
when 'null', 'nil'
nil
else
value
end
end
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment