module Dynamoid::Dumping

@private

Public Class Methods

dump_attributes(attributes, attributes_options) click to toggle source
# File lib/dynamoid/dumping.rb, line 6
def self.dump_attributes(attributes, attributes_options)
  {}.tap do |h|
    attributes.each do |attribute, value|
      h[attribute] = dump_field(value, attributes_options[attribute])
    end
  end
end
dump_field(value, options) click to toggle source
# File lib/dynamoid/dumping.rb, line 14
def self.dump_field(value, options)
  return nil if value.nil?

  dumper = find_dumper(options)

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

  dumper.process(value)
end
find_dumper(options) click to toggle source
# File lib/dynamoid/dumping.rb, line 26
def self.find_dumper(options)
  dumper_class = case options[:type]
                 when :string     then StringDumper
                 when :integer    then IntegerDumper
                 when :number     then NumberDumper
                 when :set        then SetDumper
                 when :array      then ArrayDumper
                 when :map        then MapDumper
                 when :datetime   then DateTimeDumper
                 when :date       then DateDumper
                 when :serialized then SerializedDumper
                 when :raw        then RawDumper
                 when :boolean    then BooleanDumper
                 when :binary     then BinaryDumper
                 when Class       then CustomTypeDumper
                 end

  if dumper_class.present?
    dumper_class.new(options)
  end
end