Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f2135aceeb
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (29 sloc) 0.953 kb
module ActiveRecord
class PredicateBuilder
class ArrayHandler # :nodoc:
def call(attribute, value)
return attribute.in([]) if value.empty?
values = value.map { |x| x.is_a?(Base) ? x.id : x }
ranges, values = values.partition { |v| v.is_a?(Range) }
nils, values = values.partition(&:nil?)
values_predicate =
case values.length
when 0 then NullPredicate
when 1 then attribute.eq(values.first)
else attribute.in(values)
end
unless nils.empty?
values_predicate = values_predicate.or(attribute.eq(nil))
end
array_predicates = ranges.map { |range| attribute.in(range) }
array_predicates << values_predicate
array_predicates.inject { |composite, predicate| composite.or(predicate) }
end
module NullPredicate
def self.or(other)
other
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.