class ActiveRecord::PredicateBuilder::ArrayHandler

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/active_record/relation/predicate_builder/array_handler.rbs

class ActiveRecord::PredicateBuilder::ArrayHandler
  def initialize: (ActiveRecord::PredicateBuilder predicate_builder) -> void
end

:nodoc:

def call(attribute, value)

def call(attribute, value)
  return attribute.in([]) if value.empty?
  values = value.map { |x| x.is_a?(Base) ? x.id : x }
  nils = values.extract!(&:nil?)
  ranges = values.extract! { |v| v.is_a?(Range) }
  values_predicate =
    case values.length
    when 0 then NullPredicate
    when 1 then predicate_builder.build(attribute, values.first)
    else Arel::Nodes::HomogeneousIn.new(values, attribute, :in)
    end
  unless nils.empty?
    values_predicate = values_predicate.or(attribute.eq(nil))
  end
  if ranges.empty?
    values_predicate
  else
    array_predicates = ranges.map! { |range| predicate_builder.build(attribute, range) }
    array_predicates.inject(values_predicate, &:or)
  end
end

def initialize(predicate_builder)

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (ActiveRecord::PredicateBuilder predicate_builder) -> void

This signature was generated using 3 samples from 1 application.

:nodoc:
def initialize(predicate_builder)
  @predicate_builder = predicate_builder
end