Module: Mongoid::Fields::ClassMethods
- Defined in:
- lib/mongoid/fields.rb
Instance Method Summary (collapse)
-
- (Array<String>) attribute_names
Returns an array of names for the attributes available on this object.
-
- (Field) field(name, options = {})
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.
-
- (Object) inherited(subclass)
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.
-
- (Serializable) replace_field(name, type)
Replace a field with a new type.
-
- (true, false) using_object_ids?
Convenience method for determining if we are using BSON::ObjectIds as our id.
Instance Method Details
- (Array<String>) attribute_names
Returns an array of names for the attributes available on this object.
Provides the field names in an ORM-agnostic way. Rails v3.1+ uses this meathod to automatically wrap params in JSON requests.
176 177 178 |
# File 'lib/mongoid/fields.rb', line 176 def attribute_names fields.keys end |
- (Field) field(name, options = {})
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.
195 196 197 198 199 200 201 202 203 |
# File 'lib/mongoid/fields.rb', line 195 def field(name, = {}) named = name.to_s check_field_name!(name) added = add_field(named, ) descendants.each do |subclass| subclass.add_field(named, ) end added end |
- (Object) inherited(subclass)
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.
215 216 217 218 219 |
# File 'lib/mongoid/fields.rb', line 215 def inherited(subclass) super subclass.fields, subclass.pre_processed_defaults, subclass.post_processed_defaults = fields.dup, pre_processed_defaults.dup, post_processed_defaults.dup end |
- (Serializable) replace_field(name, type)
Replace a field with a new type.
232 233 234 235 |
# File 'lib/mongoid/fields.rb', line 232 def replace_field(name, type) remove_defaults(name) add_field(name, fields[name]..merge(type: type)) end |
- (true, false) using_object_ids?
Convenience method for determining if we are using BSON::ObjectIds as our id.
246 247 248 |
# File 'lib/mongoid/fields.rb', line 246 def using_object_ids? fields["_id"].object_id_field? end |