Class: Squeel::Nodes::Predicate
- Inherits:
-
Object
- Object
- Squeel::Nodes::Predicate
- Includes:
- PredicateOperators
- Defined in:
- lib/squeel/nodes/predicate.rb
Overview
This node is essentially a container that will result in ARel predicate nodes once visited. It stores the expression (normally an attribute name, function, or operation), the ARel predicate method name, and a value. these are then interpreted when visited by the PredicateVisitor to generate a condition against the appropriate columns.
Instance Attribute Summary collapse
-
#expr ⇒ Object
readonly
The expression on the left side of this predicate.
-
#method_name ⇒ Symbol
readonly
The ARel “predication” method name, such as eq, matches, etc.
-
#value ⇒ Object
The right-hand value being considered in this predicate.
Instance Method Summary collapse
-
#%(val) ⇒ Predicate
Set the value for this predicate.
-
#eql?(other) ⇒ Boolean
(also: #==)
Object comparison.
-
#hash ⇒ Object
Implemented for equality testing.
-
#initialize(expr, method_name = :eq, value = :__undefined__) ⇒ Predicate
constructor
Create a new Predicate node with the given expression, method name, and value.
-
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
-
#value? ⇒ Boolean
Whether the value has been assigned yet.
Methods included from PredicateOperators
Constructor Details
#initialize(expr, method_name = :eq, value = :__undefined__) ⇒ Predicate
Create a new Predicate node with the given expression, method name, and value
29 30 31 |
# File 'lib/squeel/nodes/predicate.rb', line 29 def initialize(expr, method_name = :eq, value = :__undefined__) @expr, @method_name, @value = expr, method_name, value end |
Instance Attribute Details
#expr ⇒ Object (readonly)
Returns The expression on the left side of this predicate.
19 20 21 |
# File 'lib/squeel/nodes/predicate.rb', line 19 def expr @expr end |
#method_name ⇒ Symbol (readonly)
Returns The ARel “predication” method name, such as eq, matches, etc.
22 23 24 |
# File 'lib/squeel/nodes/predicate.rb', line 22 def method_name @method_name end |
#value ⇒ Object
Returns The right-hand value being considered in this predicate.
16 17 18 |
# File 'lib/squeel/nodes/predicate.rb', line 16 def value @value end |
Instance Method Details
#%(val) ⇒ Predicate
Set the value for this predicate
56 57 58 59 |
# File 'lib/squeel/nodes/predicate.rb', line 56 def %(val) @value = val self end |
#eql?(other) ⇒ Boolean Also known as: ==
Object comparison
34 35 36 37 38 39 |
# File 'lib/squeel/nodes/predicate.rb', line 34 def eql?(other) self.class.eql?(other.class) && self.expr.eql?(other.expr) && self.method_name.eql?(other.method_name) && self.value.eql?(other.value) end |
#hash ⇒ Object
Implemented for equality testing
43 44 45 |
# File 'lib/squeel/nodes/predicate.rb', line 43 def hash [self.class, expr, method_name, value].hash end |
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
65 66 67 |
# File 'lib/squeel/nodes/predicate.rb', line 65 def to_sym nil end |
#value? ⇒ Boolean
Whether the value has been assigned yet.
49 50 51 |
# File 'lib/squeel/nodes/predicate.rb', line 49 def value? @value != :__undefined__ end |