Module: Dynamoid::Fields
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/dynamoid/fields.rb
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
Instance Attribute Summary (collapse)
-
- (Object) attributes
(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)
-
- (Object) read_attribute(name)
(also: #[])
Read an attribute from an object.
-
- (Object) update_attribute(attribute, value)
Update a single attribute, saving the object afterwards.
-
- (Object) update_attributes(attributes)
Updates multiple attibutes at once, saving the object once the updates are complete.
-
- (Object) write_attribute(name, value)
(also: #[]=)
Write an attribute on the object.
Instance Attribute Details
- (Object) attributes 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.
45 46 47 |
# File 'lib/dynamoid/fields.rb', line 45 def attributes @attributes end |
Instance Method Details
- (Object) read_attribute(name) Also known as: []
Read an attribute from an object.
64 65 66 |
# File 'lib/dynamoid/fields.rb', line 64 def read_attribute(name) attributes[name.to_sym] end |
- (Object) update_attribute(attribute, value)
Update a single attribute, saving the object afterwards.
85 86 87 88 |
# File 'lib/dynamoid/fields.rb', line 85 def update_attribute(attribute, value) write_attribute(attribute, value) save end |
- (Object) update_attributes(attributes)
Updates multiple attibutes at once, saving the object once the updates are complete.
74 75 76 77 |
# File 'lib/dynamoid/fields.rb', line 74 def update_attributes(attributes) attributes.each {|attribute, value| self.write_attribute(attribute, value)} save end |
- (Object) write_attribute(name, value) Also known as: []=
Write an attribute on the object.
54 55 56 |
# File 'lib/dynamoid/fields.rb', line 54 def write_attribute(name, value) attributes[name.to_sym] = value end |