class Dynamoid::Dumping::ArrayDumper

array -> array

Constants

ALLOWED_TYPES

Public Instance Methods

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

Private Instance Methods

allowed_type?() click to toggle source
# File lib/dynamoid/dumping.rb, line 180
def allowed_type?
  ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Class)
end
element_options() click to toggle source
# File lib/dynamoid/dumping.rb, line 192
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/dumping.rb, line 184
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/dumping.rb, line 165
def process_typed_collection(array)
  if allowed_type?
    dumper = Dumping.find_dumper(element_options)
    result = array.map { |el| dumper.process(el) }

    if element_type == :string
      result.reject!(&:empty?)
    end

    result
  else
    raise ArgumentError, "Array element type #{element_type} isn't supported"
  end
end