Module: Mongoid::Serializable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Composable
- Defined in:
- build/mongoid-8.1/lib/mongoid/serializable.rb
Overview
This module provides the extra behavior for including associations in JSON and XML serialization.
Instance Method Summary collapse
-
#serializable_hash(options = nil) ⇒ Hash
Gets the document as a serializable hash, used by ActiveModel’s JSON serializer.
Instance Method Details
#serializable_hash(options = nil) ⇒ Hash
Gets the document as a serializable hash, used by ActiveModel’s JSON serializer.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'build/mongoid-8.1/lib/mongoid/serializable.rb', line 46 def serializable_hash( = nil) ||= {} attrs = {} names = field_names() method_names = Array.wrap([:methods]).map do |name| name.to_s if respond_to?(name) end.compact (names + method_names).each do |name| without_autobuild do serialize_attribute(attrs, name, names, ) end end serialize_relations(attrs, ) if [:include] attrs end |