Class: Torque::PostgreSQL::PredicateBuilder::LtreeHandler
- Inherits:
-
Object
- Object
- Torque::PostgreSQL::PredicateBuilder::LtreeHandler
- Defined in:
- lib/torque/postgresql/predicate_builder/ltree_handler.rb,
sig/torque/postgresql/predicate_builder/ltree_handler.rbs
Overview
Serves every column of the ltree extension. A value of the same kind as the column is an equality, a value of the opposite kind is a match, and an Array is a list of values as soon as its first entry is a whole one
Class Method Summary collapse
Instance Method Summary collapse
- #call(attribute, type, value) ⇒ arel_node
-
#initialize(predicate_builder) ⇒ LtreeHandler
constructor
A new instance of LtreeHandler.
Constructor Details
#initialize(predicate_builder) ⇒ LtreeHandler
Returns a new instance of LtreeHandler.
20 21 22 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 20 def initialize(predicate_builder) @predicate_builder = predicate_builder end |
Class Method Details
.candidate?(type) ⇒ Boolean
11 12 13 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 11 def candidate?(type) column_of(type).is_a?(Adapter::OID::Ltree) end |
.column_of(type) ⇒ type_caster?
15 16 17 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 15 def column_of(type) type.is_a?(ARRAY_OID) ? type.subtype : type end |
Instance Method Details
#call(attribute, type, value) ⇒ arel_node
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/torque/postgresql/predicate_builder/ltree_handler.rb', line 24 def call(attribute, type, value) @attribute = attribute @column = self.class.column_of(type) @array = type.is_a?(ARRAY_OID) @list = list?(value) values = list ? value : [value] pattern = values.any? { |entry| lquery.cast(entry)&.pattern? } pattern == lquery_column? ? equality(values) : match(values) end |