lib/mongoid/fields.rb in mongoid-3.0.0.rc vs lib/mongoid/fields.rb in mongoid-3.0.0
- old
+ new
@@ -22,13 +22,13 @@
self.post_processed_defaults = []
field(:_type, default: ->{ self.class.name if hereditary? }, type: String)
field(
:_id,
- default: ->{ BSON::ObjectId.new },
+ default: ->{ Moped::BSON::ObjectId.new },
pre_processed: true,
- type: BSON::ObjectId
+ type: Moped::BSON::ObjectId
)
alias :id :_id
alias :id= :_id=
@@ -92,10 +92,25 @@
def apply_defaults
apply_pre_processed_defaults
apply_post_processed_defaults
end
+ # 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.
+ #
+ # @example Get the field names
+ # docment.attribute_names
+ #
+ # @return [ Array<String> ] The field names
+ #
+ # @since 3.0.0
+ def attribute_names
+ self.class.attribute_names
+ end
+
# Is the document using object ids?
#
# @note Refactored from using delegate for class load performance.
#
# @example Is the document using object ids?
@@ -146,11 +161,11 @@
module ClassMethods
# 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.
+ # method to automatically wrap params in JSON requests.
#
# @example Get the field names
# Model.attribute_names
#
# @return [ Array<String> ] The field names
@@ -183,26 +198,10 @@
subclass.add_field(named, options)
end
added
end
- # 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.
- #
- # @example Inherit from this class.
- # Person.inherited(Doctor)
- #
- # @param [ Class ] subclass The inheriting class.
- #
- # @since 2.0.0.rc.6
- 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
-
# Replace a field with a new type.
#
# @example Replace the field.
# Model.replace_field("_id", String)
#
@@ -215,16 +214,16 @@
def replace_field(name, type)
remove_defaults(name)
add_field(name, fields[name].options.merge(type: type))
end
- # Convenience method for determining if we are using +BSON::ObjectIds+ as
+ # Convenience method for determining if we are using +Moped::BSON::ObjectIds+ as
# our id.
#
# @example Does this class use object ids?
# person.using_object_ids?
#
- # @return [ true, false ] If the class uses BSON::ObjectIds for the id.
+ # @return [ true, false ] If the class uses Moped::BSON::ObjectIds for the id.
#
# @since 1.0.0
def using_object_ids?
fields["_id"].object_id_field?
end