module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Quoting

Public Instance Methods

type_cast(value, column, array_member = false) click to toggle source
Calls superclass method
# File lib/restpack_service/activerecord/postgres_array_patch.rb, line 82
def type_cast(value, column, array_member = false)
  return super(value, column) unless column

  case value
  when Range
    return super(value, column) unless /range$/ =~ column.sql_type
    ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string(value)
  when NilClass
    if column.array && array_member
      'NULL'
    elsif column.array
      value
    else
      super(value, column)
    end
  when Array
    case column.sql_type
    when 'point' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.point_to_string(value)
    when 'json' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value)
    else
      return super(value, column) unless column.array
      ActiveRecord::ConnectionAdapters::PostgreSQLColumn.array_to_string(value, column, self)
    end
  when String
    return super(value, column) unless 'bytea' == column.sql_type
    { :value => value, :format => 1 }
  when Hash
    case column.sql_type
    when 'hstore' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.hstore_to_string(value)
    when 'json' then ActiveRecord::ConnectionAdapters::PostgreSQLColumn.json_to_string(value)
    else super(value, column)
    end
  when IPAddr
    return super(value, column) unless ['inet','cidr'].include? column.sql_type
    ActiveRecord::ConnectionAdapters::PostgreSQLColumn.cidr_to_string(value)
  else
    super(value, column)
  end
end