Module: Mongoid::Fields::ClassMethods
- Defined in:
- lib/mongoid/fields.rb
Instance Method Summary collapse
-
#attribute_names ⇒ Array<String>
Returns an array of names for the attributes available on this object.
-
#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.
-
#replace_field(name, type) ⇒ Serializable
Replace a field with a new type.
-
#using_object_ids? ⇒ true, false
Convenience method for determining if we are using
Moped::BSON::ObjectIds
as our id.
Instance Method Details
#attribute_names ⇒ Array<String>
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 method to automatically wrap params in JSON requests.
174 175 176 |
# File 'lib/mongoid/fields.rb', line 174 def attribute_names fields.keys 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.
193 194 195 196 197 198 199 200 201 |
# File 'lib/mongoid/fields.rb', line 193 def field(name, = {}) named = name.to_s Validators::Macro.validate(self, name, ) added = add_field(named, ) descendants.each do |subclass| subclass.add_field(named, ) end added end |
#replace_field(name, type) ⇒ Serializable
Replace a field with a new type.
214 215 216 217 |
# File 'lib/mongoid/fields.rb', line 214 def replace_field(name, type) remove_defaults(name) add_field(name, fields[name]..merge(type: type)) end |
#using_object_ids? ⇒ true, false
Convenience method for determining if we are using Moped::BSON::ObjectIds
as our id.
228 229 230 |
# File 'lib/mongoid/fields.rb', line 228 def using_object_ids? fields["_id"].object_id_field? end |