Sha256: ed543785c6b16c8ad41d2589aef390d3f7babd01639c2a71b949ac55e9f35589

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

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)
          return super unless o.val.is_a?(::Enumerable)
          quote_array(o.val, 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

15 entries across 15 versions & 1 rubygems

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