Class: ActiveRecord::Refined::AST::DistinctFrom

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

Overview

IS [NOT] DISTINCT FROM, spelled IS / IS NOT on SQLite and <=> on MySQL. NULL compares as a value here, which is what separates these from = and <>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Predicate

#!, #&, #|

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, value, negated: false) ⇒ DistinctFrom

Returns a new instance of DistinctFrom.



633
634
635
636
637
# File 'lib/active_record/refined/ast.rb', line 633

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

Instance Attribute Details

#negatedObject (readonly)

Returns the value of attribute negated.



631
632
633
# File 'lib/active_record/refined/ast.rb', line 631

def negated
  @negated
end

#operandObject (readonly)

Returns the value of attribute operand.



631
632
633
# File 'lib/active_record/refined/ast.rb', line 631

def operand
  @operand
end

#valueObject (readonly)

Returns the value of attribute value.



631
632
633
# File 'lib/active_record/refined/ast.rb', line 631

def value
  @value
end

Instance Method Details

#to_arel(table) ⇒ Object



639
640
641
642
643
644
645
646
647
# File 'lib/active_record/refined/ast.rb', line 639

def to_arel(table)
  arel_operand = to_arel_operand(operand, table)
  arel_value = value.is_a?(Node) ? value.to_arel(table) : value
  if negated
    arel_operand.is_distinct_from(arel_value)
  else
    arel_operand.is_not_distinct_from(arel_value)
  end
end