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) ⇒ In

Returns a new instance of In.



242
243
244
245
# File 'lib/active_record/refined/ast.rb', line 242

def initialize(operand, values)
  @operand = operand
  @values = values
end

Instance Attribute Details

#operandObject (readonly)

Returns the value of attribute operand.



240
241
242
# File 'lib/active_record/refined/ast.rb', line 240

def operand
  @operand
end

#valuesObject (readonly)

Returns the value of attribute values.



240
241
242
# File 'lib/active_record/refined/ast.rb', line 240

def values
  @values
end

Instance Method Details

#to_arel(table) ⇒ Object



247
248
249
250
251
252
253
254
# File 'lib/active_record/refined/ast.rb', line 247

def to_arel(table)
  arel_operand = to_arel_operand(operand, table)
  case values
  when Range then arel_operand.between(values)
  when ActiveRecord::Relation then arel_operand.in(subquery(values))
  else arel_operand.in(values)
  end
end