Class: Squeel::Nodes::Predicate
- Includes:
- Aliasing, 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
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 Aliasing
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
27 28 29 |
# File 'lib/squeel/nodes/predicate.rb', line 27 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.
17 18 19 |
# File 'lib/squeel/nodes/predicate.rb', line 17 def expr @expr end |
#method_name ⇒ Symbol (readonly)
Returns The Arel “predication” method name, such as eq, matches, etc.
20 21 22 |
# File 'lib/squeel/nodes/predicate.rb', line 20 def method_name @method_name end |
#value ⇒ Object
Returns The right-hand value being considered in this predicate.
14 15 16 |
# File 'lib/squeel/nodes/predicate.rb', line 14 def value @value end |
Instance Method Details
#%(val) ⇒ Predicate
Set the value for this predicate
53 54 55 56 |
# File 'lib/squeel/nodes/predicate.rb', line 53 def %(val) @value = val self end |
#eql?(other) ⇒ Boolean
Object comparison
32 33 34 35 36 37 |
# File 'lib/squeel/nodes/predicate.rb', line 32 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
40 41 42 |
# File 'lib/squeel/nodes/predicate.rb', line 40 def hash [@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.
62 63 64 |
# File 'lib/squeel/nodes/predicate.rb', line 62 def to_sym nil end |
#value? ⇒ Boolean
Whether the value has been assigned yet.
46 47 48 |
# File 'lib/squeel/nodes/predicate.rb', line 46 def value? @value != :__undefined__ end |