Class: ActiveRecord::Refined::AST::Comparison

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

Overview

A plain SQL comparison. The value is passed through as it is, so a Range or an Array compares against a PostgreSQL range or array column, the way Active Record's own force_equality? types do.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

#initialize(column, operator, value) ⇒ Comparison

Returns a new instance of Comparison.



2023
2024
2025
2026
2027
# File 'lib/active_record/refined/ast.rb', line 2023

def initialize(column, operator, value)
  @column = column
  @operator = operator
  @value = value
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



2021
2022
2023
# File 'lib/active_record/refined/ast.rb', line 2021

def column
  @column
end

#operatorObject (readonly)

Returns the value of attribute operator.



2021
2022
2023
# File 'lib/active_record/refined/ast.rb', line 2021

def operator
  @operator
end

#valueObject (readonly)

Returns the value of attribute value.



2021
2022
2023
# File 'lib/active_record/refined/ast.rb', line 2021

def value
  @value
end

Instance Method Details

#to_arel(table, model) ⇒ Object



2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
# File 'lib/active_record/refined/ast.rb', line 2029

def to_arel(table, model)
  arel_column = to_arel_operand(column, table, model)
  arel_value =
    case value
    when Node then value.to_arel(table, model)
    when ::Symbol then column_operand(value, table, model)
    when ActiveRecord::Relation then scalar_subquery(value)
    else quote_number(value)
    end
  arel_column.public_send(OPERATOR_MAP.fetch(operator), arel_value)
end