Module: TinyDyno::HashKeys::ClassMethods
- Defined in:
- lib/tiny_dyno/hash_keys.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 all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
-
#hash_key_is_defined?(arg = nil) ⇒ Boolean
Return true/false, depending on whether the provided argument matches a defined hash key for this document model.
-
#lookup_attribute_type(attribute_name) ⇒ Object
return the attribute_type as stored in the attribute_definitions.
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
82 83 84 |
# File 'lib/tiny_dyno/hash_keys.rb', line 82 def as_item_entry(hash_key) end |
#hash_key(name, options = {}) ⇒ Field
Defines all the fields that are accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tiny_dyno/hash_keys.rb', line 59 def hash_key(name, = {}) 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 InvalidHashKey.new(self.class, name) end # we need the accessors as well add_field(named, ) self.attribute_definitions << attribute_definition self.key_schema << key_schema # TODO # should separate that out self.hash_keys << { attr: attribute_definition[:attribute_name], attr_type: attribute_definition[:attribute_type], key_type: key_schema[:key_type], } @hash_key_fields << attribute_definition[:attribute_name] end |
#hash_key_is_defined?(arg = nil) ⇒ Boolean
Return true/false, depending on whether the provided argument matches a defined hash key for this document model
34 35 36 |
# File 'lib/tiny_dyno/hash_keys.rb', line 34 def hash_key_is_defined?(arg = nil) @hash_key_fields.include?(arg) end |
#lookup_attribute_type(attribute_name) ⇒ Object
return the attribute_type as stored in the attribute_definitions
39 40 41 42 |
# File 'lib/tiny_dyno/hash_keys.rb', line 39 def lookup_attribute_type(attribute_name) type = attribute_definitions.collect {|a| a[:attribute_type] if a[:attribute_name] == attribute_name } type.first end |