Sha256: 0ece1b71c5621afd78c822c3927d37a001704be681ea09dc026a7c8f1a6a52ca

Contents?: true

Size: 1.46 KB

Versions: 29

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Torque
  module PostgreSQL
    module Arel
      module Visitors
        # Enclose select manager with parenthesis
        # :TODO: Remove when checking the new version of Arel
        def visit_Arel_SelectManager(o, collector)
          collector << '('
          visit(o.ast, collector) << ')'
        end

        # Add ONLY modifier to query
        def visit_Arel_Nodes_JoinSource(o, collector)
          collector << 'ONLY ' if o.only?
          super
        end

        # Allow quoted arrays to get here
        def visit_Arel_Nodes_Quoted(o, collector)
          return super unless o.expr.is_a?(::Enumerable)
          quote_array(o.expr, collector)
        end

        # Allow quoted arrays to get here
        def visit_Arel_Nodes_Casted(o, collector)
          value = o.respond_to?(:val) ? o.val : o.value
          return super unless value.is_a?(::Enumerable)
          quote_array(value, collector)
        end

        ## TORQUE VISITORS
        # Allow casting any node
        def visit_Torque_PostgreSQL_Arel_Nodes_Cast(o, collector)
          visit(o.left, collector) << '::' << o.right
        end

        private

          def quote_array(value, collector)
            value = value.map(&::Arel::Nodes.method(:build_quoted))

            collector << 'ARRAY['
            visit_Array(value, collector)
            collector << ']'
          end
      end

      ::Arel::Visitors::PostgreSQL.prepend(Visitors)
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

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