Class: Ardm::ActiveRecord::PredicateBuilder::ArrayHandler
- Inherits:
-
Object
- Object
- Ardm::ActiveRecord::PredicateBuilder::ArrayHandler
- Defined in:
- lib/ardm/active_record/predicate_builder/array_handler.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#call(attribute, value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ardm/active_record/predicate_builder/array_handler.rb', line 5 def call(attribute, value) if value.include?(nil) values = value.compact if values.length == 0 attribute.eq(nil) else call(attribute, values).or(attribute.eq(nil)) end else values = value.map { |x| x.is_a?(::ActiveRecord::Base) ? x.id : x } ranges, values = values.partition { |v| v.is_a?(::Range) } array_predicates = ranges.map { |range| attribute.in(range) } array_predicates << attribute.in(values) array_predicates.inject { |composite, predicate| composite.or(predicate) } end end |