Module: Dynamoid::Fields::ClassMethods
- Defined in:
- lib/dynamoid/fields.rb
Instance Method Summary (collapse)
-
- (Object) field(name, type = :string, options = {})
Specify a field for a document.
- - (Object) range(name, type = :string)
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.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dynamoid/fields.rb', line 30 def field(name, type = :string, = {}) named = name.to_s self.attributes[name] = {:type => type}.merge() define_method(named) { read_attribute(named) } define_method("#{named}?") { !read_attribute(named).nil? } define_method("#{named}=") {|value| write_attribute(named, value) } respond_to?(:define_attribute_method) ? define_attribute_method(name) : define_attribute_methods([name]) end |
- (Object) range(name, type = :string)
41 42 43 44 |
# File 'lib/dynamoid/fields.rb', line 41 def range(name, type = :string) field(name, type) self.range_key = name end |