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,
  "B" => :binary,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ PrimaryKeyElement

Returns a new instance of PrimaryKeyElement.



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

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)


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

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