Module: Torque::PostgreSQL::PredicateBuilder::ArrayHandler
- Included in:
- ActiveRecord::PredicateBuilder::ArrayHandler, ActiveRecord::PredicateBuilder::BasicObjectHandler, Associations::AssociationScope::PredicateBuilderArray
- Defined in:
- lib/torque/postgresql/predicate_builder/array_handler.rb,
sig/torque/postgresql/predicate_builder/array_handler.rbs
Instance Method Summary collapse
Instance Method Details
#call(attribute, value) ⇒ arel_node
7 8 9 10 11 12 |
# File 'lib/torque/postgresql/predicate_builder/array_handler.rb', line 7 def call(attribute, value) return super unless array_attribute?(attribute) && PostgreSQL.config.predicate_builder.handle_array_attributes call_for_array(attribute, value) end |
#call_for_array(attribute, value) ⇒ arel_node
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/torque/postgresql/predicate_builder/array_handler.rb', line 14 def call_for_array(attribute, value) return attribute.eq(nil) if value.nil? value = value.to_a if value.is_a?(::Set) return call_with_value(attribute, value) unless value.is_a?(::Array) return call_with_empty(attribute) if value.empty? nils, values = value.map { |entry| id_of(entry) }.partition(&:nil?) return attribute.eq(nil) if values.empty? condition = call_with_array(attribute, values) nils.empty? ? condition : condition.or(attribute.eq(nil)) end |