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

Inherits:
Predicate show all
Includes:
SetSubquery
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.



1352
1353
1354
1355
1356
# File 'lib/active_record/refined/ast.rb', line 1352

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

Instance Attribute Details

#negatedObject (readonly)

Returns the value of attribute negated.



1350
1351
1352
# File 'lib/active_record/refined/ast.rb', line 1350

def negated
  @negated
end

#operandObject (readonly)

Returns the value of attribute operand.



1350
1351
1352
# File 'lib/active_record/refined/ast.rb', line 1350

def operand
  @operand
end

#valuesObject (readonly)

Returns the value of attribute values.



1350
1351
1352
# File 'lib/active_record/refined/ast.rb', line 1350

def values
  @values
end

Instance Method Details

#to_arel(table, model) ⇒ Object



1358
1359
1360
1361
1362
1363
1364
1365
1366
# File 'lib/active_record/refined/ast.rb', line 1358

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