Class: Dynamoid::PrimaryKeyTypeMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/primary_key_type_mapping.rb

Class Method Summary collapse

Class Method Details

.dynamodb_type(type, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dynamoid/primary_key_type_mapping.rb', line 6

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