Module: TinyDyno::HashKey::ClassMethods
- Defined in:
- lib/tiny_dyno/hash_key.rb
Instance Method Summary collapse
-
#hash_key(name, options = {}) ⇒ Field
Defines the primary key for the Document Only one primary key = hash_key is allowed in DynamoDB.
Instance Method Details
#hash_key(name, options = {}) ⇒ Field
Defines the primary key for the Document Only one primary key = hash_key is allowed in DynamoDB
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tiny_dyno/hash_key.rb', line 45 def hash_key(name, = {}) raise TinyDyno::Errors::OnlyOneHashKeyPermitted.new(klass: self.class, name: name) unless primary_key.empty? named = name.to_s attribute_definition = build_attribute_definition(named,[:type]) key_schema = hash_key_schema(named) unless attribute_definition_meets_spec?(attribute_definition) raise TinyDyno::Errors::InvalidHashKey.new(klass: self.class, name: name) end # we need the accessors as well add_field(named, ) self.attribute_definitions << attribute_definition self.key_schema << key_schema self.primary_key = { attribute_name: attribute_definition[:attribute_name], attribute_type: attribute_definition[:attribute_type], key_type: key_schema[:key_type], } end |