Module: TinyDyno::HashKey::ClassMethods
- Defined in:
- lib/tiny_dyno/hash_key.rb
Instance Method Summary collapse
-
#as_item_entry(hash_key) ⇒ Object
convert a hash key into a format as expected by put_item and update_item request.
-
#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
#as_item_entry(hash_key) ⇒ Object
convert a hash key into a format as expected by put_item and update_item request
57 58 59 |
# File 'lib/tiny_dyno/hash_key.rb', line 57 def as_item_entry(hash_key) end |
#hash_key(name, options = {}) ⇒ Field
Defines the primary key for the Document Only one primary key = hash_key is allowed in DynamoDB
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tiny_dyno/hash_key.rb', line 36 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 = build_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 = { attr: attribute_definition[:attribute_name], attr_type: attribute_definition[:attribute_type], key_type: key_schema[:key_type], } end |