Sha256: 28d6dd0fc298c4401d0518243e8d971c929d19ae0c8a643139700f510be1ed7b
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
module ActiveRecord class PredicateBuilder class ArrayHandler # :nodoc: def call(attribute, value) values = value.map { |x| x.is_a?(Base) ? x.id : x } nils, values = values.partition(&:nil?) if values.any? { |val| val.is_a?(Array) } ActiveSupport::Deprecation.warn "Passing a nested array to Active Record " \ "finder methods is deprecated and will be removed. Flatten your array " \ "before using it for 'IN' conditions." values = values.flatten end return attribute.in([]) if values.empty? && nils.empty? ranges, values = values.partition { |v| v.is_a?(Range) } 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.unshift(values_predicate) array_predicates.inject { |composite, predicate| composite.or(predicate) } end module NullPredicate def self.or(other) other end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activerecord-4.2.0.beta3 | lib/active_record/relation/predicate_builder/array_handler.rb |
activerecord-4.2.0.beta2 | lib/active_record/relation/predicate_builder/array_handler.rb |