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 = {}) ⇒ Object
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.
71 72 73 74 75 76 77 |
# File 'lib/mongoid/fields.rb', line 71 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 accessible on the Document For each field that is defined, a getter and setter will be added as an instance method to the Document.
35 36 37 38 39 |
# File 'lib/mongoid/fields.rb', line 35 def field(name, = {}) access = name.to_s set_field(access, ) attr_protected name if [:accessible] == false end |
#fields ⇒ Hash
Return the fields for this class.
49 50 51 |
# File 'lib/mongoid/fields.rb', line 49 def fields @fields ||= {} end |
#fields=(fields) ⇒ Object
Set the fields for the class.
61 62 63 |
# File 'lib/mongoid/fields.rb', line 61 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.
89 90 91 92 |
# File 'lib/mongoid/fields.rb', line 89 def inherited(subclass) super subclass.fields = fields.dup end |