module ActiveRecord::Type
Constants
BigInteger |
= | ActiveModel::Type::BigInteger |
Active Model BigInteger TypeAttribute type for integers that can be serialized to an unlimited number of bytes. This type is registered under the
All casting and serialization are performed in the same way as the standard |
||
Binary |
= | ActiveModel::Type::Binary |
Active Model Binary TypeAttribute type for representation of binary data. This type is registered under the Non-string values are coerced to strings using their |
||
Boolean |
= | ActiveModel::Type::Boolean |
Active Model Boolean TypeA class that behaves like a boolean type, including rules for coercion of user input.
|
||
Decimal |
= | ActiveModel::Type::Decimal |
Active Model Decimal TypeAttribute type for decimal, high-precision floating point numeric representation. It is registered under the
Numeric instances are converted to
Decimal precision defaults to 18, and can be customized when declaring an attribute:
|
||
Float |
= | ActiveModel::Type::Float |
Active Model Float TypeAttribute type for floating point numeric values. It is registered under the
Values are cast using their
|
||
ImmutableString |
= | ActiveModel::Type::ImmutableString |
Active Model ImmutableString TypeAttribute type to represent immutable strings. It casts incoming values to frozen strings.
Values are coerced to strings using their
|
||
Integer |
= | ActiveModel::Type::Integer |
Active Model Integer TypeAttribute type for integer representation. This type is registered under the
Values are cast using their
Serialization also works under the same principle. Non-numeric strings are serialized as Serialization also validates that the integer can be stored using a limited number of bytes. If it cannot, an
|
||
String |
= | ActiveModel::Type::String |
Active Model String TypeAttribute type for strings. It is registered under the This class is a specialization of |
||
Value |
= | ActiveModel::Type::Value |
Active Model Value TypeThe base class for all attribute types. This class also serves as the default type for attributes that do not specify a type. |
Public class methods
Add a new type to the registry, allowing it to be referenced as a symbol by ActiveRecord::Base.attribute
. If your type is only meant to be used with a specific database adapter, you can do so by passing adapter: :postgresql
. If your type has the same name as a native type for the current adapter, an exception will be raised unless you specify an :override
option. override: true
will cause your type to be used instead of the native type. override: false
will cause the native type to be used over yours if one exists.
Source code GitHub
# File activerecord/lib/active_record/type.rb, line 37
def register(type_name, klass = nil, **options, &block)
registry.register(type_name, klass, **options, &block)
end
Namespace
ActiveRecord::
Type:: BigInteger ActiveRecord::
Type:: Binary ActiveRecord::
Type:: Boolean ActiveRecord::
Type:: Date ActiveRecord::
Type:: DateTime ActiveRecord::
Type:: Decimal ActiveRecord::
Type:: Float ActiveRecord::
Type:: ImmutableString ActiveRecord::
Type:: Integer ActiveRecord::
Type:: Internal ActiveRecord::
Type:: Json ActiveRecord::
Type:: String ActiveRecord::
Type:: Time ActiveRecord::
Type:: Value
Definition files
activerecord/
lib/ active_record/ type.rb activerecord/
lib/ active_record/ type/ adapter_specific_registry.rb activerecord/
lib/ active_record/ type/ date.rb activerecord/
lib/ active_record/ type/ date_time.rb activerecord/
lib/ active_record/ type/ decimal_without_scale.rb
8 More Less
activerecord/
lib/ active_record/ type/ hash_lookup_type_map.rb activerecord/
lib/ active_record/ type/ internal/ timezone.rb activerecord/
lib/ active_record/ type/ json.rb activerecord/
lib/ active_record/ type/ serialized.rb activerecord/
lib/ active_record/ type/ text.rb activerecord/
lib/ active_record/ type/ time.rb activerecord/
lib/ active_record/ type/ type_map.rb activerecord/
lib/ active_record/ type/ unsigned_integer.rb