Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 92a603387c
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (26 sloc) 0.844 kb
module ActiveRecord
class PredicateBuilder
class ArrayHandler # :nodoc:
def call(attribute, value)
values = value.map { |x| x.is_a?(Base) ? x.id : x }
ranges, values = values.partition { |v| v.is_a?(Range) }
values_predicate = if values.include?(nil)
values = values.compact
case values.length
when 0
attribute.eq(nil)
when 1
attribute.eq(values.first).or(attribute.eq(nil))
else
attribute.in(values).or(attribute.eq(nil))
end
else
attribute.in(values)
end
array_predicates = ranges.map { |range| attribute.in(range) }
array_predicates << values_predicate
array_predicates.inject { |composite, predicate| composite.or(predicate) }
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.