Module: Mongoid::Fields::ClassMethods
- Defined in:
- lib/mongoid/fields.rb
Overview
:nodoc
Instance Method Summary collapse
-
#defaults ⇒ Object
Returns the default values for the fields on the document.
-
#field(name, options = {}) ⇒ Object
Defines all the fields that are accessable on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
Instance Method Details
#defaults ⇒ Object
Returns the default values for the fields on the document
36 37 38 39 40 41 42 |
# File 'lib/mongoid/fields.rb', line 36 def defaults fields.inject({}) do |defs,(field_name,field)| next(defs) if field.default.nil? defs[field_name.to_s] = field.default defs end end |
#field(name, options = {}) ⇒ Object
Defines all the fields that are accessable on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
Options:
name: The name of the field, as a Symbol
. options: A Hash
of options to supply to the Field
.
Example:
field :score, :default => 0
30 31 32 33 |
# File 'lib/mongoid/fields.rb', line 30 def field(name, = {}) access = name.to_s set_field(access, ) end |