Class: Torque::PostgreSQL::PredicateBuilder::LtreeHandler
- Inherits:
-
Object
- Object
- Torque::PostgreSQL::PredicateBuilder::LtreeHandler
- Defined in:
- lib/torque/postgresql/predicate_builder/ltree_handler.rb
Overview
A condition over an ltree column is rarely a plain equality, so the value
decides which operator to use: a plain path is compared with =, while
anything carrying an lquery marker is matched with ~
Class Method Summary collapse
-
.candidate?(value, type) ⇒ Boolean
An Array is always a single value here, either the labels of a path or the items of a pattern, so it never means a list of values the way the regular handlers would take it.
Instance Method Summary collapse
- #call(attribute, type, value) ⇒ Object
-
#initialize(predicate_builder) ⇒ LtreeHandler
constructor
A new instance of LtreeHandler.
Constructor Details
#initialize(predicate_builder) ⇒ LtreeHandler
Returns a new instance of LtreeHandler.
24 25 26 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 24 def initialize(predicate_builder) @predicate_builder = predicate_builder end |
Class Method Details
.candidate?(value, type) ⇒ Boolean
An Array is always a single value here, either the labels of a path or the items of a pattern, so it never means a list of values the way the regular handlers would take it. Objects that describe their own path are claimed as well, otherwise a record would be reduced to its primary key before it had the chance to describe itself
16 17 18 19 20 21 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 16 def candidate?(value, type) return false unless type.is_a?(Adapter::OID::Ltree) value.is_a?(::Array) || value.is_a?(LQuery) || LTree.compatible?(value) || LQuery.marker?(value) end |
Instance Method Details
#call(attribute, type, value) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 28 def call(attribute, type, value) return attribute.eq(FN.bind_with(attribute, type.cast(value))) \ unless LQuery.marker?(value) attribute.matches_lquery(pattern_for(attribute, value)) end |