module ActiveRecord::Attributes::ClassMethods
def define_attribute(
+user_provided_default+ Whether the default value should be cast using
will be called once each time a new value is needed.
Otherwise, the default will be +nil+. A proc can also be passed, and
is not passed, the previous default value (if any) will be used.
+default+ The default value to use when no value is provided. If this option
+cast_type+ The type object to use for this attribute.
+name+ The name of the attribute being defined. Expected to be a +String+.
should probably use ClassMethods#attribute.
is provided so it can be used by plugin authors, application code
ClassMethods#attribute both call this under the hood. While this method
waiting for the schema to load. Automatic schema detection and
accepts type objects, and will do its work immediately instead of
This is the low level API which sits beneath +attribute+. It only
def define_attribute( name, cast_type, default: NO_DEFAULT_PROVIDED, user_provided_default: true ) attribute_types[name] = cast_type define_default_attribute(name, default, cast_type, from_user: user_provided_default) end