Class: ActiveRecord::Refined::AST::TruthValue

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

Overview

IS TRUE, IS FALSE and their negations, which every adapter spells the same way and answers alike, NULL included.

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

Returns a new instance of TruthValue.



1311
1312
1313
1314
1315
# File 'lib/active_record/refined/ast.rb', line 1311

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

Instance Attribute Details

#negatedObject (readonly)

Returns the value of attribute negated.



1309
1310
1311
# File 'lib/active_record/refined/ast.rb', line 1309

def negated
  @negated
end

#operandObject (readonly)

Returns the value of attribute operand.



1309
1310
1311
# File 'lib/active_record/refined/ast.rb', line 1309

def operand
  @operand
end

#valueObject (readonly)

Returns the value of attribute value.



1309
1310
1311
# File 'lib/active_record/refined/ast.rb', line 1309

def value
  @value
end

Instance Method Details

#to_arel(table, model) ⇒ Object



1317
1318
1319
1320
1321
# File 'lib/active_record/refined/ast.rb', line 1317

def to_arel(table, model)
  literal = value ? Arel::Nodes::True.new : Arel::Nodes::False.new
  Arel::Nodes::InfixOperation.new(negated ? 'IS NOT' : 'IS',
    to_arel_operand(operand, table, model), literal)
end