Module: Torque::PostgreSQL::PredicateBuilder
- Included in:
- ActiveRecord::PredicateBuilder
- Defined in:
- sig/torque/postgresql/predicate_builder.rbs,
lib/torque/postgresql/predicate_builder.rb,
lib/torque/postgresql/predicate_builder/array_handler.rb,
lib/torque/postgresql/predicate_builder/ltree_handler.rb,
lib/torque/postgresql/predicate_builder/regexp_handler.rb,
lib/torque/postgresql/predicate_builder/struct_handler.rb,
lib/torque/postgresql/predicate_builder/composite_handler.rb,
lib/torque/postgresql/predicate_builder/arel_attribute_handler.rb,
lib/torque/postgresql/predicate_builder/enumerator_lazy_handler.rb,
sig/torque/postgresql/predicate_builder/array_handler.rbs,
sig/torque/postgresql/predicate_builder/ltree_handler.rbs,
sig/torque/postgresql/predicate_builder/regexp_handler.rbs,
sig/torque/postgresql/predicate_builder/struct_handler.rbs,
sig/torque/postgresql/predicate_builder/composite_handler.rbs,
sig/torque/postgresql/predicate_builder/arel_attribute_handler.rbs,
sig/torque/postgresql/predicate_builder/enumerator_lazy_handler.rbs
Overview
initialize is not declared: the handler files reopen this module before it is defined, and the runtime checker hooks it eagerly
Defined Under Namespace
Modules: ArrayHandler Classes: ArelAttributeHandler, CompositeHandler, EnumeratorLazyHandler, LtreeHandler, RegexpHandler, StructHandler
Constant Summary collapse
- ARRAY_OID =
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
Class Method Summary collapse
-
.handler_for(type, value = nil) ⇒ handler?
The handler that serves a column, either to build a condition with the given value or, without one, to resolve the parts of the column.
Instance Method Summary collapse
-
#build(attribute, value, operator = nil) ⇒ arel_node
Values described as a hash of columns or properties are turned into conditions over the column that holds them.
- #initialize ⇒ Object
-
#resolve_arel_attribute(table_name, column_name) {|arg0| ... } ⇒ arel_node
A struct or composite column stands for the table of its own parts, so a Hash given to order, group or pluck reaches a part the way where does.
Class Method Details
.handler_for(type, value = nil) ⇒ handler?
The handler that serves a column, either to build a condition with the given value or, without one, to resolve the parts of the column. The ltree handler is picked by the column alone, composite and struct also look at the value: a Hash means the parts, anything else the whole
21 22 23 24 25 26 27 28 29 |
# File 'lib/torque/postgresql/predicate_builder.rb', line 21 def self.handler_for(type, value = nil) if PostgreSQL.config.composite.enabled && CompositeHandler.candidate?(type, value) CompositeHandler elsif PostgreSQL.config.struct.enabled && StructHandler.candidate?(type, value) StructHandler elsif PostgreSQL.config.ltree.enabled && !value.nil? && LtreeHandler.candidate?(type) LtreeHandler end end |
Instance Method Details
#build(attribute, value, operator = nil) ⇒ arel_node
Values described as a hash of columns or properties are turned into conditions over the column that holds them. Whole values are left to the regular handlers, so that they are compared as a single value, and so is nil, which is a null check on every kind of column
53 54 55 56 57 58 59 60 61 |
# File 'lib/torque/postgresql/predicate_builder.rb', line 53 def build(attribute, value, operator = nil) return super if value.nil? type = Adapter::OID.unwrap(table.type(attribute.name)) handler = PredicateBuilder.handler_for(type, value) || handler_for_path(attribute, value) return super if handler.nil? handler.new(self).call(attribute, type, value) end |
#initialize ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/torque/postgresql/predicate_builder.rb', line 31 def initialize(*) super handlers = Array.wrap(PostgreSQL.config.predicate_builder.enabled).inquiry if handlers.regexp? register_handler(Regexp, RegexpHandler.new(self)) end if handlers.enumerator_lazy? register_handler(Enumerator::Lazy, EnumeratorLazyHandler.new(self)) end if handlers.arel_attribute? register_handler(::Arel::Attributes::Attribute, ArelAttributeHandler.new(self)) end end |
#resolve_arel_attribute(table_name, column_name) {|arg0| ... } ⇒ arel_node
A struct or composite column stands for the table of its own parts, so a Hash given to order, group or pluck reaches a part the way where does
65 66 67 68 69 70 71 72 73 |
# File 'lib/torque/postgresql/predicate_builder.rb', line 65 def resolve_arel_attribute(table_name, column_name, &block) return super unless table.has_column?(table_name) type = Adapter::OID.unwrap(table.type(table_name)) handler = PredicateBuilder.handler_for(type) return super if handler.nil? handler.new(self).table_for(table.arel_table[table_name], type)[column_name] end |