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 =
[ :number, :integer, :string, :datetime ]
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
-
#read_attribute(name) ⇒ Object
(also: #[])
Read an attribute from an object.
-
#update_attribute(attribute, value) ⇒ Object
Update a single attribute, saving the object afterwards.
-
#update_attributes(attributes) ⇒ Object
Updates multiple attibutes at once, saving the object once the updates are complete.
-
#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.
89 90 91 |
# File 'lib/dynamoid/fields.rb', line 89 def attributes @attributes end |
Instance Method Details
#read_attribute(name) ⇒ Object Also known as: []
Read an attribute from an object.
116 117 118 |
# File 'lib/dynamoid/fields.rb', line 116 def read_attribute(name) attributes[name.to_sym] end |
#update_attribute(attribute, value) ⇒ Object
Update a single attribute, saving the object afterwards.
137 138 139 140 |
# File 'lib/dynamoid/fields.rb', line 137 def update_attribute(attribute, value) write_attribute(attribute, value) save end |
#update_attributes(attributes) ⇒ Object
Updates multiple attibutes at once, saving the object once the updates are complete.
126 127 128 129 |
# File 'lib/dynamoid/fields.rb', line 126 def update_attributes(attributes) attributes.each {|attribute, value| self.write_attribute(attribute, value)} unless attributes.nil? || attributes.empty? save end |
#write_attribute(name, value) ⇒ Object Also known as: []=
Write an attribute on the object. Also marks the previous value as dirty.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dynamoid/fields.rb', line 98 def write_attribute(name, value) if (size = value.to_s.size) > MAX_ITEM_SIZE Dynamoid.logger.warn "DynamoDB can't store items larger than #{MAX_ITEM_SIZE} and the #{name} field has a length of #{size}." end if association = @associations[name] association.reset end attributes[name.to_sym] = value end |