class Aws::Record::Attribute
within the model class and item instances.
ability to define a database name that is separate from the name used
DynamoDB type for use in certain table and item operation calls, and the
include marshalers for type casting of item attributes, the Amazon
This class provides helper methods for Aws::Record
attributes. These
def _deep_copy(obj)
def _deep_copy(obj) Marshal.load(Marshal.dump(obj)) end
def _is_lambda?(obj)
def _is_lambda?(obj) obj.respond_to?(:call) end
def default_value
- Api: - private
def default_value if _is_lambda?(@default_value_or_lambda) type_cast(@default_value_or_lambda.call) else _deep_copy(@default_value_or_lambda) end end
def extract(dynamodb_item)
- Api: - private
def extract(dynamodb_item) dynamodb_item[@database_name] end
def initialize(name, options = {})
(**options)
-
:default_value
(Object
) -- Optional attribute used to -
:persist_nil
(Boolean
) -- Optional attribute used to -
:dynamodb_type
(String
) -- Generally used for keys and -
:database_attribute_name
(String
) -- Optional attribute -
:marshaler
(Marshaler
) -- The marshaler for this attribute.
Parameters:
-
options
(Hash
) -- -
name
(Symbol
) -- Name of the attribute. It should be a name that is
def initialize(name, options = {}) @name = name @database_name = (options[:database_attribute_name] || name).to_s @dynamodb_type = options[:dynamodb_type] @marshaler = options[:marshaler] || DefaultMarshaler @persist_nil = options[:persist_nil] @default_value_or_lambda = if options.key?(:default_value) dv = options[:default_value] _is_lambda?(dv) ? dv : type_cast(dv) end end
def persist_nil?
-
(Boolean)
- +true+ if this attribute will actively persist nil
def persist_nil? @persist_nil ? true : false end
def serialize(raw_value)
-
(Object)
- the serialized object. Return type is dependent on the
def serialize(raw_value) cast_value = type_cast(raw_value) cast_value = default_value if cast_value.nil? @marshaler.serialize(cast_value) end
def type_cast(raw_value)
-
(Object)
- the type cast object. Return type is dependent on the
def type_cast(raw_value) cast_value = @marshaler.type_cast(raw_value) cast_value = default_value if cast_value.nil? cast_value end