Class: ActiveRecord::Refined::AST::ArrayPredicate
- Defined in:
- lib/active_record/refined/ast.rb
Overview
Comparisons against a PostgreSQL array column, named after the Ruby methods that mean the same thing: member? is Enumerable's element test, superset? and subset? are Set's whole-array containment, and intersect? is Array's "any element in common". Each name maps to one operator; the elements are rendered as an array literal, which PostgreSQL coerces to the column's element type, so any expression works as the operand and no schema lookup is needed.
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
Class Method Summary collapse
-
.elements(arg, method_name) ⇒ Object
The whole-array comparisons take the collection kinds their namesakes compare against: an Array, or a Set for the Set methods.
Instance Method Summary collapse
-
#initialize(operand, operator, elements) ⇒ ArrayPredicate
constructor
A new instance of ArrayPredicate.
- #to_arel(table) ⇒ Object
Methods inherited from Predicate
Methods inherited from Node
Constructor Details
#initialize(operand, operator, elements) ⇒ ArrayPredicate
Returns a new instance of ArrayPredicate.
671 672 673 674 675 |
# File 'lib/active_record/refined/ast.rb', line 671 def initialize(operand, operator, elements) @operand = operand @operator = operator @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
669 670 671 |
# File 'lib/active_record/refined/ast.rb', line 669 def elements @elements end |
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
669 670 671 |
# File 'lib/active_record/refined/ast.rb', line 669 def operand @operand end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
669 670 671 |
# File 'lib/active_record/refined/ast.rb', line 669 def operator @operator end |
Class Method Details
.elements(arg, method_name) ⇒ Object
The whole-array comparisons take the collection kinds their namesakes compare against: an Array, or a Set for the Set methods.
660 661 662 663 664 665 666 667 |
# File 'lib/active_record/refined/ast.rb', line 660 def self.elements(arg, method_name) case arg when ::Array then arg when ::Set then arg.to_a else raise ArgumentError, "#{method_name} takes an Array or Set of elements" end end |
Instance Method Details
#to_arel(table) ⇒ Object
677 678 679 680 681 682 683 684 685 |
# File 'lib/active_record/refined/ast.rb', line 677 def to_arel(table) arel_operand = to_arel_operand(operand, table) quoted = Arel::Nodes.build_quoted(array_literal) case operator when :"@>" then Arel::Nodes::Contains.new(arel_operand, quoted) when :"&&" then Arel::Nodes::Overlaps.new(arel_operand, quoted) else Arel::Nodes::InfixOperation.new(operator, arel_operand, quoted) end end |