class ActiveModel::Type::Value
default type for attributes that do not specify a type.
The base class for all attribute types. This class also serves as the
= Active Model Value Type
def ==(other)
def ==(other) self.class == other.class && precision == other.precision && scale == other.scale && limit == other.limit end
def as_json(*)
def as_json(*) raise NoMethodError end
def assert_valid_value(_)
def assert_valid_value(_) end
def binary? # :nodoc:
their use, and see if they can be removed entirely.
These predicates are not documented, as I need to look further into
def binary? # :nodoc: false end
def cast(value)
Value#cast_value.
ActiveRecord::AttributeMethods::Read#read_attribute. See also:
The return value of this method will be returned from
from.
There is currently no way to differentiate between which source it came
be a string from the form builder, or a ruby object passed to a setter.
Type casts a value from user input (e.g. from a setter). This value may
def cast(value) cast_value(value) unless value.nil? end
def cast_value(value) # :doc:
values except +nil+.
behavior for user and database inputs. Called by Value#cast for
Convenience method for types which do not need separate type casting
def cast_value(value) # :doc: value end
def changed?(old_value, new_value, _new_value_before_type_cast)
and +new_value+ will always be type-cast. Types should not need to
Determines whether a value has changed for dirty checking. +old_value+
def changed?(old_value, new_value, _new_value_before_type_cast) old_value != new_value end
def changed_in_place?(raw_old_value, new_value)
+deserialize+.
+raw_old_value+ The original value, before being passed to
+new_value+
- pass +raw_old_value+ to Value#deserialize and compare it to
or
+raw_old_value+
- pass +new_value+ to Value#serialize and compare it to
to either:
which could be mutated, you should override this method. You will need
read. Returns +false+ by default. If your type returns an object
Determines whether the mutable value has been modified since it was
def changed_in_place?(raw_old_value, new_value) false end
def deserialize(value)
implementation just calls Value#cast.
ActiveRecord::AttributeMethods::Read#read_attribute. The default
return value of this method will be returned from
Converts a value from database input to the appropriate ruby type. The
def deserialize(value) cast(value) end
def force_equality?(_value) # :nodoc:
def force_equality?(_value) # :nodoc: false end
def hash
def hash [self.class, precision, scale, limit].hash end
def initialize(precision: nil, limit: nil, scale: nil)
these settings. It uses them for equality comparison and hash key
limit, and scale. The Value base class does not define behavior for
Initializes a type with three basic configuration settings: precision,
def initialize(precision: nil, limit: nil, scale: nil) super() @precision = precision @scale = scale @limit = limit end
def map(value, &) # :nodoc:
def map(value, &) # :nodoc: value end
def mutable? # :nodoc:
def mutable? # :nodoc: false end
def serializable?(value)
value parameter is a Ruby boolean, but may return +false+ if the value
by the database. For example a boolean type can return +true+ if the
Returns true if this type can convert +value+ to a type that is usable
def serializable?(value) true end
def serialize(value)
+String+, +Numeric+, +Date+, +Time+, +Symbol+, +true+, +false+, or
to understand. The returned value from this method should be a
Casts a value from the ruby type to a type that the database knows how
def serialize(value) value end
def serialized? # :nodoc:
def serialized? # :nodoc: false end
def type
Returns the unique type name as a Symbol. Subclasses should override
def type end
def type_cast_for_schema(value) # :nodoc:
hoping to remove it entirely.
Type casts a value for schema dumping. This method is private, as we are
def type_cast_for_schema(value) # :nodoc: value.inspect end
def value_constructed_by_mass_assignment?(_value) # :nodoc:
def value_constructed_by_mass_assignment?(_value) # :nodoc: false end