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)
- - (Object) remove_field(field)
- - (Object) table(options)
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.
31 32 33 34 35 36 37 38 |
# File 'lib/dynamoid/fields.rb', line 31 def field(name, type = :string, = {}) named = name.to_s self.attributes = attributes.merge(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) } end |
- (Object) range(name, type = :string)
40 41 42 43 |
# File 'lib/dynamoid/fields.rb', line 40 def range(name, type = :string) field(name, type) self.range_key = name end |
- (Object) remove_field(field)
53 54 55 56 57 58 59 |
# File 'lib/dynamoid/fields.rb', line 53 def remove_field(field) field = field.to_sym attributes.delete(field) or raise "No such field" remove_method field remove_method :#{field}=" remove_method :#{field}?" end |
- (Object) table(options)
45 46 47 48 49 50 51 |
# File 'lib/dynamoid/fields.rb', line 45 def table() #a default 'id' column is created when Dynamoid::Document is included unless(attributes.has_key? hash_key) remove_field :id field(hash_key) end end |