Class: Torque::PostgreSQL::PredicateBuilder::ArelAttributeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/torque/postgresql/predicate_builder/arel_attribute_handler.rb,
sig/torque/postgresql/predicate_builder/arel_attribute_handler.rbs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ ArelAttributeHandler

Returns a new instance of ArelAttributeHandler.

Parameters:

  • (Object)


12
13
14
# File 'lib/torque/postgresql/predicate_builder/arel_attribute_handler.rb', line 12

def initialize(*)
  # There is no need to use or save the predicate builder here
end

Class Method Details

.call(*args) ⇒ arel_node

Shortcut

Parameters:

  • attribute (arel_node)
  • value (arel_node)

Returns:

  • (arel_node)


8
9
10
# File 'lib/torque/postgresql/predicate_builder/arel_attribute_handler.rb', line 8

def self.call(*args)
  new.call(*args)
end

Instance Method Details

#call(attribute, value) ⇒ arel_node

Parameters:

  • attribute (arel_node)
  • value (arel_node)

Returns:

  • (arel_node)


16
17
18
19
20
21
22
23
# File 'lib/torque/postgresql/predicate_builder/arel_attribute_handler.rb', line 16

def call(attribute, value)
  case
  when array_typed?(attribute) && array_typed?(value) then attribute.overlaps(value)
  when array_typed?(attribute) then value.eq(FN.any(attribute))
  when array_typed?(value) then attribute.eq(FN.any(value))
  else attribute.eq(value)
  end
end