Module: TinyDyno::HashKeys::ClassMethods

Defined in:
lib/tiny_dyno/hash_keys.rb

Instance Method Summary collapse

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.

Examples:

Define a field.

field :score, :type => Integer, :default => 0

Parameters:

  • name (Symbol)

    The name of the field.

  • options (Hash) (defaults to: {})

    The options to pass to the field.

Options Hash (options):

  • :type (Class)

    The type of the field.

  • :label (String)

    The label for the field.

  • :default (Object, Proc)

    The field’s default

Returns:

  • (Field)

    The generated field



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, options = {})
  named = name.to_s
  attribute_definition = build_attribute_definition(named,options[: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, options)
  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

Examples:

Hash key is defined?

Person.hash_key_is_defined?(:id)

Parameters:

  • name, (String)

    the name of the hash key

Returns:

  • (Boolean)

    True, False



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