Class: AWS::DynamoDB::PrimaryKeyElement

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/dynamo_db/primary_key_element.rb

Constant Summary collapse

ATTRIBUTE_TYPES =
{
  "S" => :string,
  "N" => :number
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ PrimaryKeyElement

Returns a new instance of PrimaryKeyElement.



27
28
29
30
# File 'lib/aws/dynamo_db/primary_key_element.rb', line 27

def initialize(hash)
  @name = hash[:name] || hash["AttributeName"]
  @type = hash[:type] || ATTRIBUTE_TYPES[hash["AttributeType"]]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/aws/dynamo_db/primary_key_element.rb', line 18

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/aws/dynamo_db/primary_key_element.rb', line 20

def type
  @type
end

Class Method Details

.from_description(description) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws/dynamo_db/primary_key_element.rb', line 32

def self.from_description(description)
  (name, type, *extra) = description.to_a.flatten

  raise(ArgumentError,
        "key element may contain only one name/type pair") unless
    extra.empty?

  raise ArgumentError, "unsupported type #{type.inspect}" unless
    ATTRIBUTE_TYPES.values.include?(type.to_sym)

  new(:name => name.to_s, :type => type)
end