class Dynamoid::Undumping::ArrayUndumper

Constants

ALLOWED_TYPES

Public Instance Methods

process(array) click to toggle source
# File lib/dynamoid/undumping.rb, line 150
def process(array)
  if @options.key?(:of)
    process_typed_collection(array)
  else
    array.is_a?(Array) ? array : Array(array)
  end
end

Private Instance Methods

allowed_type?() click to toggle source
# File lib/dynamoid/undumping.rb, line 169
def allowed_type?
  ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Class)
end
element_options() click to toggle source
# File lib/dynamoid/undumping.rb, line 181
def element_options
  if @options[:of].is_a?(Hash)
    @options[:of][element_type].dup.tap do |options|
      options[:type] = element_type
    end
  else
    { type: element_type }
  end
end
element_type() click to toggle source
# File lib/dynamoid/undumping.rb, line 173
def element_type
  if @options[:of].is_a?(Hash)
    @options[:of].keys.first
  else
    @options[:of]
  end
end
process_typed_collection(array) click to toggle source
# File lib/dynamoid/undumping.rb, line 160
def process_typed_collection(array)
  if allowed_type?
    undumper = Undumping.find_undumper(element_options)
    array.map { |el| undumper.process(el) }
  else
    raise ArgumentError, "Array element type #{element_type} isn't supported"
  end
end