Module: Dynamoid::Fields
Overview
All fields on a Dynamoid::Document must be explicitly defined – if you have fields in the database that are not specified with field, then they will be ignored.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- PERMITTED_KEY_TYPES =
Types allowed in indexes:
%i[ number integer string datetime serialized ].freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
(also: #raw_attributes)
You can access the attributes of an object directly on its attributes method, which is by default an empty hash.
Instance Method Summary collapse
-
#attributes_before_type_cast ⇒ Object
Returns a hash of attributes before typecasting.
-
#read_attribute(name) ⇒ Object
(also: #[])
Read an attribute from an object.
-
#read_attribute_before_type_cast(name) ⇒ Object
Returns the value of the attribute identified by name before typecasting.
-
#write_attribute(name, value) ⇒ Object
(also: #[]=)
Write an attribute on the object.
Instance Attribute Details
#attributes ⇒ Object Also known as: raw_attributes
You can access the attributes of an object directly on its attributes method, which is by default an empty hash.
114 115 116 |
# File 'lib/dynamoid/fields.rb', line 114 def attributes @attributes end |
Instance Method Details
#attributes_before_type_cast ⇒ Object
Returns a hash of attributes before typecasting
150 151 152 |
# File 'lib/dynamoid/fields.rb', line 150 def attributes_before_type_cast @attributes_before_type_cast end |
#read_attribute(name) ⇒ Object Also known as: []
Read an attribute from an object.
144 145 146 |
# File 'lib/dynamoid/fields.rb', line 144 def read_attribute(name) attributes[name.to_sym] end |
#read_attribute_before_type_cast(name) ⇒ Object
Returns the value of the attribute identified by name before typecasting
157 158 159 160 161 |
# File 'lib/dynamoid/fields.rb', line 157 def read_attribute_before_type_cast(name) return nil unless name.respond_to?(:to_sym) @attributes_before_type_cast[name.to_sym] end |
#write_attribute(name, value) ⇒ Object Also known as: []=
Write an attribute on the object. Also marks the previous value as dirty.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dynamoid/fields.rb', line 123 def write_attribute(name, value) name = name.to_sym if association = @associations[name] association.reset end attribute_will_change!(name) # Dirty API @attributes_before_type_cast[name] = value value_casted = TypeCasting.cast_field(value, self.class.attributes[name]) attributes[name] = value_casted end |