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 ActiveRecord's own force_equality? types do.

Constant Summary collapse

OPERATOR_MAP =
{
  :== => :eq, :!= => :not_eq,
  :> => :gt, :>= => :gteq, :< => :lt, :<= => :lteq
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(column, operator, value) ⇒ Comparison

Returns a new instance of Comparison.



205
206
207
208
209
# File 'lib/active_record/refined/ast.rb', line 205

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

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



203
204
205
# File 'lib/active_record/refined/ast.rb', line 203

def column
  @column
end

#operatorObject (readonly)

Returns the value of attribute operator.



203
204
205
# File 'lib/active_record/refined/ast.rb', line 203

def operator
  @operator
end

#valueObject (readonly)

Returns the value of attribute value.



203
204
205
# File 'lib/active_record/refined/ast.rb', line 203

def value
  @value
end

Instance Method Details

#to_arel(table) ⇒ Object



211
212
213
214
215
# File 'lib/active_record/refined/ast.rb', line 211

def to_arel(table)
  arel_column = to_arel_operand(column, table)
  arel_value = value.is_a?(Node) ? value.to_arel(table) : value
  arel_column.public_send(OPERATOR_MAP.fetch(operator), arel_value)
end