Module: Aws::Record::Attributes

Included in:
Aws::Record
Defined in:
lib/aws-record/record/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(sub_class) ⇒ Object


18
19
20
21
22
23
# File 'lib/aws-record/record/attributes.rb', line 18

def self.included(sub_class)
  sub_class.extend(ClassMethods)
  model_attributes = ModelAttributes.new(self)
  sub_class.instance_variable_set("@attributes", model_attributes)
  sub_class.instance_variable_set("@keys", KeyAttributes.new(model_attributes))
end

Instance Method Details

#initialize(attr_values = {}) ⇒ Aws::Record

Base initialization method for a new item. Optionally, allows you to provide initial attribute values for the model. You do not need to provide all, or even any, attributes at item creation time.

Examples:

Usage Example

class MyModel
  include Aws::Record
  integer_attr :id,   hash_key: true
  string_attr  :name, range_key: true
  string_attr  :body
end

item = MyModel.new(id: 1, name: "Quick Create")

Parameters:

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

    Attribute symbol/value pairs for any initial attribute values you wish to set.

Returns:


42
43
44
45
46
47
48
49
50
# File 'lib/aws-record/record/attributes.rb', line 42

def initialize(attr_values = {})
  opts = {
    track_mutations: self.class.mutation_tracking_enabled?
  }
  @data = ItemData.new(self.class.attributes, opts)
  attr_values.each do |attr_name, attr_value|
    send("#{attr_name}=", attr_value)
  end
end

#to_hHash

Returns a hash representation of the attribute data.

Returns:

  • (Hash)

    Map of attribute names to raw values.


55
56
57
# File 'lib/aws-record/record/attributes.rb', line 55

def to_h
  @data.hash_copy
end