Module: Dynamoid::Fields::ClassMethods

Defined in:
lib/dynamoid/fields.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) field(name, type = :string, options = {})

Specify a field for a document. Its type determines how it is coerced when read in and out of the datastore: default is string, but you can also specify :integer, :float, :set, :array: datetime, and :serialized.

Parameters:

  • name (Symbol)

    the name of the field

  • type (Symbol) (defaults to: :string)

    the type of the field (one of :integer, :float, :set, :array: datetime, or :serialized)

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

    any additional options for the field

Since:

  • 0.2.0



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dynamoid/fields.rb', line 29

def field(name, type = :string, options = {})
  named = name.to_s
  self.attributes[name] = {:type => type}.merge(options)
  define_method(named) do
    read_attribute(named)
  end
  define_method("#{named}=") do |value|
    write_attribute(named, value)
  end
  define_method("#{named}?") do
    !read_attribute(named).nil?
  end
end