Module: Dynamoid::Document::ClassMethods
- Defined in:
- lib/dynamoid/document.rb
Instance Method Summary (collapse)
- - (Object) attr_readonly(*read_only_attributes)
-
- (Dynamoid::Document) build(attrs = {})
Initialize a new object.
-
- (Object) count
Returns the number of items for this class.
-
- (Dynamoid::Document) create(attrs = {})
Initialize a new object and immediately save it to the database.
-
- (Dynamoid::Document) create!(attrs = {})
Initialize a new object and immediately save it to the database.
-
- (Boolean) exists?(id_or_conditions = {})
Does this object exist?.
-
- (Object) hash_key
Returns the id field for this class.
-
- (Object) read_capacity
Returns the read_capacity for this table.
-
- (Object) table(options = {})
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
-
- (Object) write_capacity
Returns the write_capacity for this table.
Instance Method Details
- (Object) attr_readonly(*read_only_attributes)
35 36 37 |
# File 'lib/dynamoid/document.rb', line 35 def attr_readonly(*read_only_attributes) self.read_only_attributes.concat read_only_attributes.map(&:to_s) end |
- (Dynamoid::Document) build(attrs = {})
Initialize a new object.
96 97 98 |
# File 'lib/dynamoid/document.rb', line 96 def build(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs) : new(attrs) end |
- (Object) count
Returns the number of items for this class.
63 64 65 |
# File 'lib/dynamoid/document.rb', line 63 def count Dynamoid::Adapter::AwsSdk.count(table_name) end |
- (Dynamoid::Document) create(attrs = {})
Initialize a new object and immediately save it to the database.
74 75 76 |
# File 'lib/dynamoid/document.rb', line 74 def create(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save) : new(attrs).tap(&:save) end |
- (Dynamoid::Document) create!(attrs = {})
Initialize a new object and immediately save it to the database. Raise an exception if persistence failed.
85 86 87 |
# File 'lib/dynamoid/document.rb', line 85 def create!(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save!) : new(attrs).tap(&:save!) end |
- (Boolean) exists?(id_or_conditions = {})
Does this object exist?
107 108 109 110 111 112 |
# File 'lib/dynamoid/document.rb', line 107 def exists?(id_or_conditions = {}) case id_or_conditions when Hash then ! where(id_or_conditions).all.empty? else !! find(id_or_conditions) end end |
- (Object) hash_key
Returns the id field for this class.
56 57 58 |
# File 'lib/dynamoid/document.rb', line 56 def hash_key [:key] || :id end |
- (Object) read_capacity
Returns the read_capacity for this table.
42 43 44 |
# File 'lib/dynamoid/document.rb', line 42 def read_capacity [:read_capacity] || Dynamoid::Config.read_capacity end |
- (Object) table(options = {})
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
30 31 32 33 |
# File 'lib/dynamoid/document.rb', line 30 def table( = {}) self. = super if defined? super end |
- (Object) write_capacity
Returns the write_capacity for this table.
49 50 51 |
# File 'lib/dynamoid/document.rb', line 49 def write_capacity [:write_capacity] || Dynamoid::Config.write_capacity end |