module Dynamoid::TypeCasting
@private
Public Class Methods
cast_attributes(attributes, attributes_options)
click to toggle source
# File lib/dynamoid/type_casting.rb, line 6 def self.cast_attributes(attributes, attributes_options) {}.tap do |h| attributes.symbolize_keys.each do |attribute, value| h[attribute] = cast_field(value, attributes_options[attribute]) end end end
cast_field(value, options)
click to toggle source
# File lib/dynamoid/type_casting.rb, line 14 def self.cast_field(value, options) return value if options.nil? return nil if value.nil? type_caster = find_type_caster(options) if type_caster.nil? raise ArgumentError, "Unknown type #{options[:type]}" end type_caster.process(value) end
find_type_caster(options)
click to toggle source
# File lib/dynamoid/type_casting.rb, line 26 def self.find_type_caster(options) type_caster_class = case options[:type] when :string then StringTypeCaster when :integer then IntegerTypeCaster when :number then NumberTypeCaster when :set then SetTypeCaster when :array then ArrayTypeCaster when :map then MapTypeCaster when :datetime then DateTimeTypeCaster when :date then DateTypeCaster when :raw then RawTypeCaster when :serialized then SerializedTypeCaster when :boolean then BooleanTypeCaster when :binary then BinaryTypeCaster when Class then CustomTypeCaster end if type_caster_class.present? type_caster_class.new(options) end end