Sha256: 9c11cd11a700425f92811f8445421384e298370f44c3e09aee61981608df2869

Contents?: true

Size: 1.08 KB

Versions: 2

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.is_a?(::Enumerable)
            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

2 entries across 2 versions & 1 rubygems

Version Path
torque-postgresql-1.0.1 lib/torque/postgresql/adapter/quoting.rb
torque-postgresql-1.0.0 lib/torque/postgresql/adapter/quoting.rb