Instantiate this class and add one, or an Array
of fully rendered resource objects to it via the API described in the base
class, Hoodoo::Presenters::Embedding::Embeddable. You
can then pass it to the likes of Hoodoo::Presenters::Base.render_in
via the options
parameter to have the embed data included in
the fully rendered end result.
When a request arrives to embed data for a particular resource or list of resources (in which case, do the following for each item in that list):
-
Render the embedded resource(s)
-
Create an instance of this class
-
Add the rendered resource representations using this class's API
-
Use Hoodoo::Presenters::Base.render_in to render the final, target resource, passing in the embed collection via the
options
Hash.
Simple example:
embeds = Hoodoo::Presenters::Embedding::Embeds.new
embeds.add_one( 'balance', rendered_balance )
embeds.add_many( 'vouchers', rendered_voucher_array )
Returns the top-level resource key used for reference data, as per the API
documentation - which is the String
_embed
.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 128 def resource_key '_embed' end
Called from add_many in the base class to make sure the right data is being supplied. Raises an exception if it gets worried.
thing
-
The value that'll be stored; should be an Array of Hashes but only the first array entry is checked, for speed.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 151 def validate_many( thing ) unless thing.is_a?( ::Array ) raise "Hoodoo::Presenters::Embedding::Embeds\#add_many requires an Array, but was given an instance of #{ thing.class }" end unless thing[ 0 ].nil? || thing[ 0 ].is_a?( ::Hash ) raise "Hoodoo::Presenters::Embedding::Embeds\#add_many requires an Array of rendered resource Hashes, but the first Array entry is an instance of #{ thing[ 0 ].class }" end end
Called from add_one in the base class to make sure the right data is being supplied. Raises an exception if it gets worried.
thing
-
The value that'll be stored; should be a Hash.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 139 def validate_one( thing ) unless thing.is_a?( ::Hash ) raise "Hoodoo::Presenters::Embedding::Embeds\#add_one requires a rendered resource Hash, but was given an instance of #{ thing.class }" end end