Module: Dynamoid::Document::ClassMethods

Defined in:
lib/dynamoid/document.rb

Instance Method Summary (collapse)

Instance Method Details

- (Dynamoid::Document) build(attrs = {})

Initialize a new object.

Parameters:

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

    Attributes with which to create the object.

Returns:

Since:

  • 0.2.0



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

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

- (Dynamoid::Document) create(attrs = {})

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



23
24
25
26
27
28
29
# File 'lib/dynamoid/document.rb', line 23

def create(attrs = {})
  obj = self.new(attrs)
  obj.run_callbacks(:create) do
    obj.save
  end
  obj
end

- (Dynamoid::Document) create!(attrs = {})

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



38
39
40
41
42
43
44
# File 'lib/dynamoid/document.rb', line 38

def create!(attrs = {})
  obj = self.new(attrs)
  obj.run_callbacks(:create) do
    obj.save!
  end
  obj
end

- (Boolean) exists?(id)

Does this object exist?

Parameters:

  • id (String)

    the id of the object

Returns:

  • (Boolean)

    true/false

Since:

  • 0.2.0



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

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