Module: Mongoid::Serialization
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Serialization
- Included in:
- Components
- Defined in:
- lib/mongoid/serialization.rb
Overview
This module provides the extra behaviour for including relations in JSON and XML serialization.
Class Method Summary collapse
-
.mongoize(object, klass = Object) ⇒ Object
Serialize the provided object into a Mongo friendly value, using the field serialization method for the passed in type.
Instance Method Summary collapse
-
#serializable_hash(options = nil) ⇒ Hash
Gets the document as a serializable hash, used by ActiveModel’s JSON and XML serializers.
Class Method Details
.mongoize(object, klass = Object) ⇒ Object
Serialize the provided object into a Mongo friendly value, using the field serialization method for the passed in type. If no type is given then we assume generic object serialization, which just returns the value itself.
52 53 54 |
# File 'lib/mongoid/serialization.rb', line 52 def mongoize(object, klass = Object) Fields::Mappings.for(klass).instantiate(:mongoize).serialize(object) end |
Instance Method Details
#serializable_hash(options = nil) ⇒ Hash
Gets the document as a serializable hash, used by ActiveModel’s JSON and XML serializers. This override is just to be able to pass the :include and :except options to get associations in the hash.
29 30 31 32 33 34 |
# File 'lib/mongoid/serialization.rb', line 29 def serializable_hash( = nil) ||= {} super().tap do |attrs| serialize_relations(attrs, ) if [:include] end end |