Module: ActiveRecord::Refined::AST::Connectives

Included in:
Operation, Predicate, Sql
Defined in:
lib/active_record/refined/ast.rb

Overview

&, | and ! -- AND, OR and NOT, what joins conditions into one and negates them. A predicate carries them, and so do Sql and Operation, whose SQL is read as a condition the moment it is combined like one.

Included in those three and never imported into a refinement, as Predications is: a bare symbol is a column, and a column is not a condition.

Instance Method Summary collapse

Instance Method Details

#!AST::Predicate

NOT (condition), negating anything; the negations SQL spells for itself, IS NOT NULL and its kin, have names of their own under Predications. Being here rather than only on Predicate is what keeps ! on Sql and Operation from falling through to Ruby's own, which would quietly answer false.

Examples:

Author.where { !:name.like?("A%") }

Returns:



772
773
774
# File 'lib/active_record/refined/ast.rb', line 772

def !
  Not.new(self)
end

#&(other) ⇒ AST::Predicate

AND.

Examples:

Author.where { :age.between?(20, 40) & (:country == "JP") }
Post.where { sql("score > 0") & (:published == true) }

Returns:



752
753
754
# File 'lib/active_record/refined/ast.rb', line 752

def &(other)
  And.new(self, other)
end

#|(other) ⇒ AST::Predicate

OR.

Returns:



758
759
760
# File 'lib/active_record/refined/ast.rb', line 758

def |(other)
  Or.new(self, other)
end