Class: ActiveRecord::Refined::AST::Member

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

Overview

Containment in a PostgreSQL array column. The two flavors of "does it contain this?" split by name the way Ruby's own classes do: include? is String's substring match (LIKE), member? is Enumerable's element test, which String does not have. The elements are rendered as an array literal, which PostgreSQL coerces to the column's element type, so any expression works as the operand and no schema lookup is needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, element) ⇒ Member

Returns a new instance of Member.



337
338
339
340
# File 'lib/active_record/refined/ast.rb', line 337

def initialize(operand, element)
  @operand = operand
  @elements = element.is_a?(::Array) ? element : [element]
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



335
336
337
# File 'lib/active_record/refined/ast.rb', line 335

def elements
  @elements
end

#operandObject (readonly)

Returns the value of attribute operand.



335
336
337
# File 'lib/active_record/refined/ast.rb', line 335

def operand
  @operand
end

Instance Method Details

#to_arel(table) ⇒ Object



342
343
344
345
# File 'lib/active_record/refined/ast.rb', line 342

def to_arel(table)
  arel_operand = to_arel_operand(operand, table)
  arel_operand.contains(Arel::Nodes.build_quoted(array_literal))
end