Sha256: b621fe338437c8dc21ec0a43b46e263002a196a2161a172de59857153a94edc2

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

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|
        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, nodes.build_quoted(other, self))
        end
      end

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
torque-postgresql-1.1.8 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.7 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.0.3 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.0.2 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.6 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.5 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.0.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-2.0.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.4 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.3 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.2 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.1.0 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.0.1 lib/torque/postgresql/arel/infix_operation.rb
torque-postgresql-1.0.0 lib/torque/postgresql/arel/infix_operation.rb