Method: ActiveRecord::ConnectionAdapters::Quoting#type_cast

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

#type_cast(value) ⇒ Object

Cast a value to a type that the database understands. For example, SQLite does not understand dates, so this method will convert a Date to a String.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'activerecord/lib/active_record/connection_adapters/abstract/quoting.rb', line 94

def type_cast(value)
  case value
  when Symbol, ActiveSupport::Multibyte::Chars, Type::Binary::Data
    value.to_s
  when true       then unquoted_true
  when false      then unquoted_false
  # BigDecimals need to be put in a non-normalized form and quoted.
  when BigDecimal then value.to_s("F")
  when nil, Numeric, String then value
  when Type::Time::Value then quoted_time(value)
  when Date, Time then quoted_date(value)
  else raise TypeError, "can't cast #{value.class.name}"
  end
end