Method: Hypermodel::Serializers::Mongoid#embedded_resources
- Defined in:
- lib/hypermodel/serializers/mongoid.rb
#embedded_resources ⇒ Object
Public: Returns a Hash with the embedded resources attributes. It will be used by Hypermodel::Resource.
An example of an embedded resource could be the reviews of a post, or the addresses of a company. But you can really embed whatever you like.
An example of the returning Hash could be the following:
{"comments"=>
[
{"_id"=>"4fb941cb82b4d46162000007", "body"=>"Comment 1"},
{"_id"=>"4fb941cb82b4d46162000008", "body"=>"Comment 2"}
]
}
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hypermodel/serializers/mongoid.rb', line 71 def return {} if .empty? .inject({}) do |acc, (name, )| if attributes = (name) @attributes.delete(name) acc.update(name => attributes) end acc end end |