Module: Dynamoid::Document::ClassMethods
- Defined in:
- lib/dynamoid/document.rb
Instance Method Summary collapse
-
#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
#build(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object.
82 83 84 |
# File 'lib/dynamoid/document.rb', line 82 def build(attrs = {}) new(attrs) end |
#create(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object and immediately save it to the database.
60 61 62 |
# File 'lib/dynamoid/document.rb', line 60 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.
71 72 73 |
# File 'lib/dynamoid/document.rb', line 71 def create!(attrs = {}) new(attrs).tap(&:save!) end |
#exists?(id) ⇒ Boolean
Does this object exist?
93 94 95 |
# File 'lib/dynamoid/document.rb', line 93 def exists?(id) !! find(id) end |
#hash_key ⇒ Object
Returns the id field for this class.
49 50 51 |
# File 'lib/dynamoid/document.rb', line 49 def hash_key [:key] || :id end |
#read_capacity ⇒ Object
Returns the read_capacity for this table.
35 36 37 |
# File 'lib/dynamoid/document.rb', line 35 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.
28 29 30 |
# File 'lib/dynamoid/document.rb', line 28 def table( = {}) self. = end |