module Dynamoid::Document::ClassMethods

Public Instance Methods

attr_readonly(*read_only_attributes) click to toggle source
# 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
build(attrs = {}) click to toggle source

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
count() click to toggle source

Returns the number of items for this class.

@since 0.6.1

# File lib/dynamoid/document.rb, line 63
def count
  Dynamoid.adapter.count(table_name)
end
create(attrs = {}) click to toggle source

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 = {})
  build(attrs).tap(&:save)
end
create!(attrs = {}) click to toggle source

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 = {})
  build(attrs).tap(&:save!)
end
exists?(id_or_conditions = {}) click to toggle source

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
hash_key() click to toggle source

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
read_capacity() click to toggle source

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
table(options = {}) click to toggle source

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

Calls superclass method
# File lib/dynamoid/document.rb, line 30
def table(options = {})
  self.options = options
  super if defined? super
end
write_capacity() click to toggle source

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