class Aws::Plugins::DynamoDBSimpleAttributes::ValueTranslator

@api private

Public Class Methods

new(shape, mode) click to toggle source

@param [Seahorse::Model::Shapes::Shape] shape @param [Symbol<:marshal,:unmarshal>] mode

# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 142
def initialize(shape, mode)
  @shape = shape
  @mode = mode
end

Public Instance Methods

apply(values) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 147
def apply(values)
  structure(@shape, values) if @shape
end

Private Instance Methods

list(shape, values) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 168
def list(shape, values)
  return values unless values.is_a?(Array)
  values.inject([]) do |list, value|
    list << translate(shape.member, value)
  end
end
map(shape, values) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 175
def map(shape, values)
  return values unless values.is_a?(Hash)
  values.each.with_object({}) do |(key, value), hash|
    hash[key] = translate(shape.value, value)
  end
end
structure(shape, values) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 153
def structure(shape, values)
  if values.is_a?(Struct)
    values.members.each do |key|
      values[key] = translate(shape.member(key), values[key])
    end
    values
  elsif values.is_a?(Hash)
    values.each.with_object({}) do |(key, value), hash|
      hash[key] = translate(shape.member(key), value)
    end
  else
    values
  end
end
translate(shape, value) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 182
def translate(shape, value)
  if shape.name == 'AttributeValue'
    DynamoDB::AttributeValue.new.send(@mode, value)
  else
    translate_complex(shape, value)
  end
end
translate_complex(shape, value) click to toggle source
# File lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb, line 190
def translate_complex(shape, value)
  case shape
  when Seahorse::Model::Shapes::Structure then structure(shape, value)
  when Seahorse::Model::Shapes::List then list(shape, value)
  when Seahorse::Model::Shapes::Map then map(shape, value)
  else value
  end
end