Sha256: 0b70f7614461db496949b197ea8851bec4c093d834ebfc19b545f82ce81043b9

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Dynamoid
  class PrimaryKeyTypeMapping
    def self.dynamodb_type(type, options)
      if type.is_a?(Class)
        type = type.respond_to?(:dynamoid_field_type) ? type.dynamoid_field_type : :string
      end

      case type
      when :string, :serialized
        :string
      when :integer, :number
        :number
      when :datetime
        string_format = if options[:store_as_string].nil?
                          Dynamoid::Config.store_datetime_as_string
                        else
                          options[:store_as_string]
                        end
        string_format ? :string : :number
      when :date
        string_format = if options[:store_as_string].nil?
                          Dynamoid::Config.store_date_as_string
                        else
                          options[:store_as_string]
                        end
        string_format ? :string : :number
      else
        raise Errors::UnsupportedKeyType, "#{type} cannot be used as a type of table key attribute"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dynamoid-3.5.0 lib/dynamoid/primary_key_type_mapping.rb
dynamoid-3.4.1 lib/dynamoid/primary_key_type_mapping.rb
dynamoid-3.4.0 lib/dynamoid/primary_key_type_mapping.rb
dynamoid-3.3.0 lib/dynamoid/primary_key_type_mapping.rb
dynamoid-3.2.0 lib/dynamoid/primary_key_type_mapping.rb