module Dynamoid::Undumping

@private

Public Class Methods

find_undumper(options) click to toggle source
# File lib/dynamoid/undumping.rb, line 29
def self.find_undumper(options)
  undumper_class = case options[:type]
                   when :string     then StringUndumper
                   when :integer    then IntegerUndumper
                   when :number     then NumberUndumper
                   when :set        then SetUndumper
                   when :array      then ArrayUndumper
                   when :map        then MapUndumper
                   when :datetime   then DateTimeUndumper
                   when :date       then DateUndumper
                   when :raw        then RawUndumper
                   when :serialized then SerializedUndumper
                   when :boolean    then BooleanUndumper
                   when :binary     then BinaryUndumper
                   when Class       then CustomTypeUndumper
                   end

  if undumper_class.present?
    undumper_class.new(options)
  end
end
undump_attributes(attributes, attributes_options) click to toggle source
# File lib/dynamoid/undumping.rb, line 6
def self.undump_attributes(attributes, attributes_options)
  {}.tap do |h|
    # ignore existing attributes not declared in document class
    attributes.symbolize_keys
      .select { |attribute| attributes_options.key?(attribute) }
      .each do |attribute, value|
      h[attribute] = undump_field(value, attributes_options[attribute])
    end
  end
end
undump_field(value, options) click to toggle source
# File lib/dynamoid/undumping.rb, line 17
def self.undump_field(value, options)
  return nil if value.nil?

  undumper = find_undumper(options)

  if undumper.nil?
    raise ArgumentError, "Unknown type #{options[:type]}"
  end

  undumper.process(value)
end