Module: Dynamoid::Document::ClassMethods
- Defined in:
- lib/dynamoid/document.rb
Instance Method Summary collapse
- #attr_readonly(*read_only_attributes) ⇒ Object
-
#build(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object.
-
#create(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object and immediately save it to the database.
-
#create!(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object and immediately save it to the database.
-
#exists?(id) ⇒ Boolean
Does this object exist?.
-
#hash_key ⇒ Object
Returns the id field for this class.
-
#read_capacity ⇒ Object
Returns the read_capacity for this table.
-
#table(options = {}) ⇒ Object
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
-
#write_capacity ⇒ Object
Returns the write_capacity for this table.
Instance Method Details
#attr_readonly(*read_only_attributes) ⇒ Object
33 34 35 |
# File 'lib/dynamoid/document.rb', line 33 def attr_readonly(*read_only_attributes) self.read_only_attributes.concat read_only_attributes.map(&:to_s) end |
#build(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object.
87 88 89 |
# File 'lib/dynamoid/document.rb', line 87 def build(attrs = {}) new(attrs) end |
#create(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object and immediately save it to the database.
65 66 67 |
# File 'lib/dynamoid/document.rb', line 65 def create(attrs = {}) new(attrs).tap(&:save) end |
#create!(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object and immediately save it to the database. Raise an exception if persistence failed.
76 77 78 |
# File 'lib/dynamoid/document.rb', line 76 def create!(attrs = {}) new(attrs).tap(&:save!) end |
#exists?(id) ⇒ Boolean
Does this object exist?
98 99 100 |
# File 'lib/dynamoid/document.rb', line 98 def exists?(id) !! find(id) end |
#hash_key ⇒ Object
Returns the id field for this class.
54 55 56 |
# File 'lib/dynamoid/document.rb', line 54 def hash_key [:key] || :id end |
#read_capacity ⇒ Object
Returns the read_capacity for this table.
40 41 42 |
# File 'lib/dynamoid/document.rb', line 40 def read_capacity [:read_capacity] || Dynamoid::Config.read_capacity end |
#table(options = {}) ⇒ Object
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
29 30 31 |
# File 'lib/dynamoid/document.rb', line 29 def table( = {}) self. = end |