module Dynamoid::Document::ClassMethods
Public Instance Methods
# 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
Initialize a new object.
@param [Hash] attrs Attributes with which to create the object.
@return [Dynamoid::Document] the new document
@since 0.2.0
# File lib/dynamoid/document.rb, line 87 def build(attrs = {}) new(attrs) end
Initialize a new object and immediately save it to the database.
@param [Hash] attrs Attributes with which to create the object.
@return [Dynamoid::Document] the saved document
@since 0.2.0
# File lib/dynamoid/document.rb, line 65 def create(attrs = {}) new(attrs).tap(&:save) end
Initialize a new object and immediately save it to the database. Raise an exception if persistence failed.
@param [Hash] attrs Attributes with which to create the object.
@return [Dynamoid::Document] the saved document
@since 0.2.0
# File lib/dynamoid/document.rb, line 76 def create!(attrs = {}) new(attrs).tap(&:save!) end
Does this object exist?
@param [String] id the id of the object
@return [Boolean] true/false
@since 0.2.0
# File lib/dynamoid/document.rb, line 98 def exists?(id) !! find(id) end
Returns the id field for this class.
@since 0.4.0
# File lib/dynamoid/document.rb, line 54 def hash_key options[:key] || :id end
Returns the read_capacity
for this table.
@since 0.4.0
# File lib/dynamoid/document.rb, line 40 def read_capacity options[:read_capacity] || Dynamoid::Config.read_capacity end
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
@param [Hash] options options to pass for this table @option options [Symbol] :name the name for the table; this still gets namespaced @option options [Symbol] :id id column for the table @option options [Integer] :read_capacity set the read capacity for the table; does not work on existing tables @option options [Integer] :write_capacity set the write capacity for the table; does not work on existing tables
@since 0.4.0
# File lib/dynamoid/document.rb, line 29 def table(options = {}) self.options = options end
Returns the write_capacity
for this table.
@since 0.4.0
# File lib/dynamoid/document.rb, line 47 def write_capacity options[:write_capacity] || Dynamoid::Config.write_capacity end