Module: ActiveAttr::TypecastedAttributes
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes, Typecasting
- Included in:
- Model
- Defined in:
- lib/active_attr/typecasted_attributes.rb
Overview
TypecastedAttributes allows types to be declared for your attributes
Types are declared by passing the :type option to the attribute class method. After a type is declared, attribute readers will convert any assigned attribute value to the declared type. If the assigned value cannot be cast, nil will be returned instead. You can access the original assigned value using the before_type_cast methods.
See Typecasting for the currently supported types.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#attribute_before_type_cast(name) ⇒ Object?
Read the raw attribute value.
Methods included from Typecasting
#typecast_attribute, #typecaster_for
Methods included from Attributes
#==, #attributes, filter_attributes, filter_attributes=, #inspect, #read_attribute, #write_attribute
Instance Method Details
#attribute_before_type_cast(name) ⇒ Object?
Read the raw attribute value
48 49 50 51 |
# File 'lib/active_attr/typecasted_attributes.rb', line 48 def attribute_before_type_cast(name) @attributes ||= {} @attributes[name.to_s] end |