Module: Mongoid::Fields::ClassMethods
- Defined in:
- lib/mongoid/fields.rb
Overview
:nodoc
Instance Method Summary collapse
-
#defaults ⇒ Hash
Returns the default values for the fields on the document.
-
#field(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.
-
#fields ⇒ Hash
Return the fields for this class.
-
#fields=(fields) ⇒ Object
Set the fields for the class.
-
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behaviour of the old class_inheritable_accessor that was deprecated in Rails edge.
Instance Method Details
#defaults ⇒ Hash
Returns the default values for the fields on the document.
72 73 74 75 76 77 78 |
# File 'lib/mongoid/fields.rb', line 72 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 = {}) ⇒ 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.
37 38 39 40 |
# File 'lib/mongoid/fields.rb', line 37 def field(name, = {}) access = name.to_s set_field(access, ) end |
#fields ⇒ Hash
Return the fields for this class.
50 51 52 |
# File 'lib/mongoid/fields.rb', line 50 def fields @fields ||= {} end |
#fields=(fields) ⇒ Object
Set the fields for the class.
62 63 64 |
# File 'lib/mongoid/fields.rb', line 62 def fields=(fields) @fields = fields end |
#inherited(subclass) ⇒ Object
When inheriting, we want to copy the fields from the parent class and set the on the child to start, mimicking the behaviour of the old class_inheritable_accessor that was deprecated in Rails edge.
90 91 92 93 |
# File 'lib/mongoid/fields.rb', line 90 def inherited(subclass) super subclass.fields = fields.dup end |