Class: ActiveRecord::Refined::AST::In

Inherits:
Predicate show all
Defined in:
lib/active_record/refined/ast.rb

Overview

IN for a list of values, BETWEEN for a range, IN (SELECT ...) for a relation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, values, negated: false) ⇒ In

Returns a new instance of In.



534
535
536
537
538
# File 'lib/active_record/refined/ast.rb', line 534

def initialize(operand, values, negated: false)
  @operand = operand
  @values = values
  @negated = negated
end

Instance Attribute Details

#negatedObject (readonly)

Returns the value of attribute negated.



532
533
534
# File 'lib/active_record/refined/ast.rb', line 532

def negated
  @negated
end

#operandObject (readonly)

Returns the value of attribute operand.



532
533
534
# File 'lib/active_record/refined/ast.rb', line 532

def operand
  @operand
end

#valuesObject (readonly)

Returns the value of attribute values.



532
533
534
# File 'lib/active_record/refined/ast.rb', line 532

def values
  @values
end

Instance Method Details

#to_arel(table) ⇒ Object



540
541
542
543
544
545
546
547
548
# File 'lib/active_record/refined/ast.rb', line 540

def to_arel(table)
  arel_operand = to_arel_operand(operand, table)
  if values.is_a?(Range)
    arel_operand.public_send(negated ? :not_between : :between, values)
  else
    arg = values.is_a?(ActiveRecord::Relation) ? subquery(values) : values
    arel_operand.public_send(negated ? :not_in : :in, arg)
  end
end