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.

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.



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

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 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