Instantiate this class and add one, or an Array
of UUID strings 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 reference data included
in the fully rendered end result.
When a request arrives to reference UUID data for a particular resource or list of resources (in which case, do the following for each item in that list):
-
Obtain the referenced resource UUID(s)
-
Create an instance of this class
-
Add the UUIDs using this class's API
-
Use Hoodoo::Presenters::Base.render_in to render the final, target resource, passing in the reference collection via the
options
Hash.
Simple example:
references = Hoodoo::Presenters::Embedding::References.new
references.add_one( 'member', member_uuid )
references.add_many( 'memberships', array_of_membership_uuids )
Returns the top-level resource key used for reference data, as per the API
documentation - which is the String
_reference
.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 194 def resource_key '_reference' 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 valid UUIDs, but only the first array entry is checked, for speed.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 218 def validate_many( thing ) unless thing.is_a?( ::Array ) raise "Hoodoo::Presenters::Embedding::References\#add_many requires an Array, but was given an instance of #{ thing.class }" end unless thing[ 0 ].nil? || Hoodoo::UUID.valid?( thing[ 0 ] ) raise 'Hoodoo::Presenters::Embedding::References#add_many requires an Array of valid UUID strings, but the first Array entry is invalid' 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 valid UUID.
Source: show
# File lib/hoodoo/presenters/embedding.rb, line 205 def validate_one( thing ) unless Hoodoo::UUID.valid?( thing ) raise 'Hoodoo::Presenters::Embedding::References#add_one requires a valid UUID String, but the given value is invalid' end end