Class: Aws::DynamoDB::AttributeValue::Marshaler Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/dynamodb/attribute_value.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

STRINGY_TEST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

lambda { |val| val.respond_to?(:to_str) }

Instance Method Summary collapse

Instance Method Details

#format(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aws-sdk-core/dynamodb/attribute_value.rb', line 26

def format(obj)
  case obj
  when Hash
    obj.each.with_object(m:{}) do |(key, value), map|
      map[:m][key.to_s] = format(value)
    end
  when Array
    obj.each.with_object(l:[]) do |value, list|
      list[:l] << format(value)
    end
  when String then { s: obj }
  when Symbol then { s: obj.to_s }
  when STRINGY_TEST then { s: obj.to_str }
  when Numeric then { n: obj.to_s }
  when StringIO, IO then { b: obj }
  when Set then format_set(obj)
  when true, false then { bool: obj }
  when nil then { null: true }
  else
    msg = "unsupported type, expected Hash, Array, Set, String, Numeric, "
    msg << "IO, true, false, or nil, got #{obj.class.name}"
    raise ArgumentError, msg
  end
end