Module: DynamoRecord::Document

Extended by:
ActiveSupport::Concern
Includes:
Fields, Finders, Persistence, Query
Defined in:
lib/dynamo_record/document.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Persistence

#destroy, #save

Methods included from Fields

#read_attribute, #write_attribute

Instance Attribute Details

#new_recordObject

Returns the value of attribute new_record.



22
23
24
# File 'lib/dynamo_record/document.rb', line 22

def new_record
  @new_record
end

Instance Method Details

#attributes=(hash) ⇒ Object



43
44
45
46
47
# File 'lib/dynamo_record/document.rb', line 43

def attributes=(hash)
  hash.each do |k, v|
    send("#{k}=", v)
  end
end

#initialize(attrs = {}, ignore_unknown_field = false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dynamo_record/document.rb', line 24

def initialize(attrs = {}, ignore_unknown_field = false)
  @new_record = true
  @attributes = {}

  # Set default
  self.class.attributes.each do |key, value|
    send("#{key}=", value[:options][:default]) if value[:options][:default]
  end

  load(attrs, ignore_unknown_field)      
end

#load(attrs, ignore_unknown_field = false) ⇒ Object



36
37
38
39
40
41
# File 'lib/dynamo_record/document.rb', line 36

def load(attrs, ignore_unknown_field=false)
  attrs.each do |key, value|
    next if ignore_unknown_field && !respond_to?("#{key}=")
    send("#{key}=", value)
  end
end