module Dynamoid::Document::ClassMethods
Public Instance Methods
# 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
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 96 def build(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs) : new(attrs) end
Returns the number of items for this class.
@since 0.6.1
# File lib/dynamoid/document.rb, line 63 def count Dynamoid::Adapter.adapter.count(table_name) 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 74 def create(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save) : 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 85 def create!(attrs = {}) attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save!) : new(attrs).tap(&:save!) end
Does this object exist?
@param [Mixed] id_or_conditions the id of the object or a hash with the options to filter from.
@return [Boolean] true/false
@since 0.2.0
# 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
Returns the id field for this class.
@since 0.4.0
# File lib/dynamoid/document.rb, line 56 def hash_key options[:key] || :id end
Returns the read_capacity
for this table.
@since 0.4.0
# File lib/dynamoid/document.rb, line 42 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 30 def table(options = {}) self.options = options super if defined? super end
Returns the write_capacity
for this table.
@since 0.4.0
# File lib/dynamoid/document.rb, line 49 def write_capacity options[:write_capacity] || Dynamoid::Config.write_capacity end