Sha256: 887b99c8244b4b7fd882b9bff7bddce7da4e8608e59cac78f62ba62a3135040d

Contents?: true

Size: 1.42 KB

Versions: 31

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Torque
  module PostgreSQL
    module Arel
      nodes = ::Arel::Nodes
      inflix = nodes::InfixOperation
      visitors = ::Arel::Visitors::PostgreSQL
      default_alias = :visit_Arel_Nodes_InfixOperation

      Math = Module.new
      INFLIX_OPERATION = {
        'Overlaps'          => :'&&',
        'Contains'          => :'@>',
        'ContainedBy'       => :'<@',
        'HasKey'            => :'?',
        'HasAllKeys'        => :'?&',
        'HasAnyKeys'        => :'?|',
        'StrictlyLeft'      => :'<<',
        'StrictlyRight'     => :'>>',
        'DoesntRightExtend' => :'&<',
        'DoesntLeftExtend'  => :'&>',
        'AdjacentTo'        => :'-|-',
      }.freeze

      INFLIX_OPERATION.each do |operator_name, operator|
        next if nodes.const_defined?(operator_name)

        klass = Class.new(inflix)
        klass.send(:define_method, :initialize) { |*args| super(operator, *args) }

        nodes.const_set(operator_name, klass)
        visitors.send(:alias_method, :"visit_Arel_Nodes_#{operator_name}", default_alias)

        # Don't worry about quoting here, if the right side is something that
        # doesn't need quoting, it will leave it as it is
        Math.send(:define_method, operator_name.underscore) do |other|
          klass.new(self, other)
        end
      end

      ::Arel::Nodes::Node.include(Math)
      ::Arel::Attribute.include(Math)
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
torque-postgresql-3.4.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.5 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.4.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.3.3 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.4 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.3.2 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.3 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.3.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.3.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.2.2 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.2 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.2.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.4.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.2.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.1.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.3.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.0.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.2.4 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-3.0.0 lib/torque/postgresql/arel/infix_operation.rb