Module: Dynamoid::Document::ClassMethods

Defined in:
lib/dynamoid/document.rb

Instance Method Summary collapse

Instance Method Details

#attr_readonly(*read_only_attributes) ⇒ Object



33
34
35
# 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

#build(attrs = {}) ⇒ Dynamoid::Document

Initialize a new object.

Parameters:

  • attrs (Hash) (defaults to: {})

    Attributes with which to create the object.

Returns:

Since:

  • 0.2.0



87
88
89
# File 'lib/dynamoid/document.rb', line 87

def build(attrs = {})
  new(attrs)
end

#create(attrs = {}) ⇒ Dynamoid::Document

Initialize a new object and immediately save it to the database.

Parameters:

  • attrs (Hash) (defaults to: {})

    Attributes with which to create the object.

Returns:

Since:

  • 0.2.0



65
66
67
# File 'lib/dynamoid/document.rb', line 65

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.

Parameters:

  • attrs (Hash) (defaults to: {})

    Attributes with which to create the object.

Returns:

Since:

  • 0.2.0



76
77
78
# File 'lib/dynamoid/document.rb', line 76

def create!(attrs = {})
  new(attrs).tap(&:save!)
end

#exists?(id) ⇒ Boolean

Does this object exist?

Parameters:

  • id (String)

    the id of the object

Returns:

  • (Boolean)

    true/false

Since:

  • 0.2.0



98
99
100
# File 'lib/dynamoid/document.rb', line 98

def exists?(id)
  !! find(id)
end

#hash_keyObject

Returns the id field for this class.

Since:

  • 0.4.0



54
55
56
# File 'lib/dynamoid/document.rb', line 54

def hash_key
  options[:key] || :id
end

#read_capacityObject

Returns the read_capacity for this table.

Since:

  • 0.4.0



40
41
42
# File 'lib/dynamoid/document.rb', line 40

def read_capacity
  options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    options to pass for this table

Options Hash (options):

  • :name (Symbol)

    the name for the table; this still gets namespaced

  • :id (Symbol)

    id column for the table

  • :read_capacity (Integer)

    set the read capacity for the table; does not work on existing tables

  • :write_capacity (Integer)

    set the write capacity for the table; does not work on existing tables

Since:

  • 0.4.0



29
30
31
# File 'lib/dynamoid/document.rb', line 29

def table(options = {})
  self.options = options
end

#write_capacityObject

Returns the write_capacity for this table.

Since:

  • 0.4.0



47
48
49
# File 'lib/dynamoid/document.rb', line 47

def write_capacity
  options[:write_capacity] || Dynamoid::Config.write_capacity
end