Module: Dynamoid::Dumping

Defined in:
lib/dynamoid/dumping.rb

Defined Under Namespace

Modules: DeepSanitizeHelper Classes: ArrayDumper, Base, BinaryDumper, BooleanDumper, CustomTypeDumper, DateDumper, DateTimeDumper, IntegerDumper, MapDumper, NumberDumper, RawDumper, SerializedDumper, SetDumper, StringDumper

Class Method Summary collapse

Class Method Details

.dump_attributes(attributes, attributes_options) ⇒ Object



6
7
8
9
10
11
12
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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