Sha256: e552a5dca0815338039a33fbe2e7b222abbdecea77c5761d8121cb69f2ff10f7

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

module Torque
  module PostgreSQL
    module Adapter
      module Quoting

        Name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name

        # Quotes type names for use in SQL queries.
        def quote_type_name(string, schema = nil)
          name_schema, table = string.to_s.scan(/[^".\s]+|"[^"]*"/)
          if table.nil?
            table = name_schema
            name_schema = nil
          end

          schema = schema || name_schema || 'public'
          Name.new(schema, table).quoted
        end

        def quote_default_expression(value, column)
          if value.class <= Array
            quote(value) + '::' + column.sql_type
          else
            super
          end
        end

        private

          def _quote(value)
            return super unless value.is_a?(Array)

            values = value.map(&method(:quote))
            "ARRAY[#{values.join(','.freeze)}]"
          end

          def _type_cast(value)
            return super unless value.is_a?(Array)
            value.map(&method(:quote)).join(','.freeze)
          end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
torque-postgresql-1.1.8 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.7 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-2.0.3 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-2.0.2 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.6 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.5 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-2.0.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-2.0.0 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.4 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.3 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.2 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.1.0 lib/torque/postgresql/adapter/quoting.rb