class ActiveModel::Type::Value
def ==(other)
def ==(other) self.class == other.class && precision == other.precision && scale == other.scale && limit == other.limit 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 hash
def hash [self.class, precision, scale, limit].hash end
def initialize(precision: nil, limit: nil, scale: nil)
def initialize(precision: nil, limit: nil, scale: nil) @precision = precision @scale = scale @limit = limit end
def map(value) # :nodoc:
def map(value) # :nodoc: yield value 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 type # :nodoc:
def type # :nodoc: 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