Class: Unity::DynamoDB::AttributeDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/unity/dynamodb/attribute_deserializer.rb,
lib/unity/dynamodb/attribute_deserializer/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(hash) ⇒ Object



10
11
12
# File 'lib/unity/dynamodb/attribute_deserializer.rb', line 10

def self.call(hash)
  new.call(hash)
end

Instance Method Details

#call(hash) ⇒ Object



14
15
16
17
18
# File 'lib/unity/dynamodb/attribute_deserializer.rb', line 14

def call(hash)
  return unless hash.is_a?(Hash)

  hash.transform_values { |v| translate(v) }
end

#translate(arg) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/unity/dynamodb/attribute_deserializer.rb', line 20

def translate(arg)
  type = arg.keys[0]
  value = arg[type]
  case type
  when 'N' then BigDecimal(value)
  when 'L'
    value.map { |item| translate(item) }
  when 'SS'
    Set.new(value)
  when 'NS'
    Set.new(value.map(&:to_s))
  when 'M'
    value.transform_values { |item| translate(item) }
  when 'S' then value.to_s
  when 'B' then StringIO.new(Base64.decode64(value))
  when 'BS'
    Set.new(value.map { |item| StringIO.new(Base64.decode64(item)) })
  when 'NULL' then nil
  when 'BOOL' then value
  else value
  end
end