lib/dynamoid/persistence.rb
# Undump a string value for a given type.
#
# @since 0.2.0
Undump a string value for a given type.
Undump a string value for a given type .
def undump_field(value, options)
        if (field_class = options[:type]).is_a?(Class)
          raise 'Dynamoid class-type fields do not support default values' if options[:default]
          if field_class.respond_to?(:dynamoid_load)
            field_class.dynamoid_load(value)
          end
        elsif options[:type] == :serialized
          if value.is_a?(String)
            options[:serializer] ? options[:serializer].load(value) : YAML.load(value)
          else
            value
          end
        else
          if value.nil? && (default_value = options[:default])
            value = default_value.respond_to?(:call) ? default_value.call : default_value
          end
          if !value.nil?
            case options[:type]
              when :string
                value.to_s
              when :integer
                Integer(value)
              when :number
                BigDecimal.new(value.to_s)
              when :array
                value.to_a
              when :set
                Set.new(value)
              when :datetime
                if value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time)
                  value
                else
                  Time.at(value).to_datetime
                end
              when :boolean
                if value == 't' || value == true
                  true
                elsif value == 'f' || value == false
                  false
                else
                  raise ArgumentError, "Boolean column neither true nor false"
                end
              else
                raise ArgumentError, "Unknown type #{options[:type]}"
            end
          end
        end
      end
def undump_field ( value , options ) if ( field_class = options [ :type ] ) . is_a? ( Class ) raise 'Dynamoid class-type fields do not support default values' if options [ :default ] if field_class . respond_to? ( :dynamoid_load ) field_class . dynamoid_load ( value ) end elsif options [ :type ] == :serialized if value . is_a? ( String ) options [ :serializer ] ? options [ :serializer ] . load ( value ) : YAML . load ( value ) else value end else if value . nil? && ( default_value = options [ :default ] ) value = default_value . respond_to? ( :call ) ? default_value . call : default_value end if ! value . nil? case options [ :type ] when :string value . to_s when :integer Integer ( value ) when :number BigDecimal . new ( value . to_s ) when :array value . to_a when :set Set . new ( value ) when :datetime if value . is_a? ( Date ) || value . is_a? ( DateTime ) || value . is_a? ( Time ) value else Time . at ( value ) . to_datetime end when :boolean if value == 't' || value == true true elsif value == 'f' || value == false false else raise ArgumentError , "Boolean column neither true nor false" end else raise ArgumentError , "Unknown type #{options[:type]}" end end end end
Undump a string value for a given type.
Undump a string value for a given type .
# persisted as 't', but because undump is called during initialize it can come in as true
value
options
since
None