module Aws::Record::Attributes

Public Class Methods

included(sub_class) click to toggle source
# 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
new(attr_values = {}) click to toggle source

@example 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")

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.

@param [Hash] attr_values Attribute symbol/value pairs for any initial

attribute values you wish to set.

@return [Aws::Record] An item instance for your model.

# 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

Public Instance Methods

to_h() click to toggle source

Returns a hash representation of the attribute data.

@return [Hash] Map of attribute names to raw values.

# File lib/aws-record/record/attributes.rb, line 55
def to_h
  @data.hash_copy
end