Class: Squeel::Visitors::PredicateVisitor
- Includes:
- PredicateVisitation
- Defined in:
- lib/squeel/visitors/predicate_visitor.rb
Direct Known Subclasses
Constant Summary
Constants included from PredicateVisitation
Squeel::Visitors::PredicateVisitation::FALSE_SQL, Squeel::Visitors::PredicateVisitation::TRUE_SQL
Constants inherited from Visitor
Instance Attribute Summary
Attributes inherited from Visitor
Instance Method Summary collapse
-
#implies_hash_context_shift?(v) ⇒ Boolean
private
Whether the given value implies a context change.
-
#visit_Hash(o, parent) ⇒ Array
private
Visit a Hash.
-
#visit_without_hash_context_shift(k, v, parent) ⇒ Object
private
Create a predicate for a given key/value pair.
Methods included from PredicateVisitation
#arel_predicate_for, #attribute_in_array, #attribute_not_in_array, #quote_for_node, #visit_Squeel_Nodes_Predicate, #visit_Squeel_Nodes_Sifter
Methods inherited from Visitor
#accept, #can_visit?, can_visit?, #hash_context_shifted?, #initialize, #quote, #quoted?, #visit, #visit_ActiveRecord_Base, #visit_ActiveRecord_Relation, #visit_Array, #visit_Squeel_Nodes_And, #visit_Squeel_Nodes_As, #visit_Squeel_Nodes_Function, #visit_Squeel_Nodes_Grouping, #visit_Squeel_Nodes_KeyPath, #visit_Squeel_Nodes_Literal, #visit_Squeel_Nodes_Not, #visit_Squeel_Nodes_Operation, #visit_Squeel_Nodes_Or, #visit_Squeel_Nodes_Stub, #visit_Symbol, #visit_passthrough, #visit_with_hash_context_shift
Constructor Details
This class inherits a constructor from Squeel::Visitors::Visitor
Instance Method Details
#implies_hash_context_shift?(v) ⇒ Boolean (private)
Returns Whether the given value implies a context change.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/squeel/visitors/predicate_visitor.rb', line 30 def implies_hash_context_shift?(v) case v when Hash, Nodes::Predicate, Nodes::Unary, Nodes::Binary, Nodes::Nary, Nodes::Sifter true when Nodes::KeyPath can_visit?(v.endpoint) && !(Nodes::Stub === v.endpoint) else false end end |
#visit_Hash(o, parent) ⇒ Array (private)
Visit a Hash. This entails iterating through each key and value and visiting each value in turn.
17 18 19 20 21 22 23 24 25 |
# File 'lib/squeel/visitors/predicate_visitor.rb', line 17 def visit_Hash(o, parent) predicates = super if predicates.size > 1 Arel::Nodes::Grouping.new(Arel::Nodes::And.new predicates) else predicates.first end end |
#visit_without_hash_context_shift(k, v, parent) ⇒ Object (private)
Create a predicate for a given key/value pair. If the value is a Symbol, Stub, or KeyPath, it’s converted to a table.column for the predicate value.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/squeel/visitors/predicate_visitor.rb', line 49 def visit_without_hash_context_shift(k, v, parent) case v when Nodes::Stub, Symbol v = contextualize(parent)[v.to_s] when Nodes::KeyPath # If we could visit the endpoint, we wouldn't be here v = contextualize(traverse(v, parent))[v.endpoint.to_s] end case k when Nodes::Predicate visit(k % quote_for_node(k.expr, v), parent) when Nodes::Function, Nodes::Literal arel_predicate_for(visit(k, parent), quote(v), parent) when Nodes::KeyPath visit(k % quote_for_node(k.endpoint, v), parent) else attr_name = k.to_s attribute = if !hash_context_shifted? && attr_name.include?('.') table_name, attr_name = attr_name.split(/\./, 2) Arel::Table.new(table_name.to_s, :engine => engine)[attr_name.to_s] else contextualize(parent)[attr_name] end arel_predicate_for(attribute, v, parent) end end |