class Hoodoo::Presenters::Embedding::Embeddable
The Embeddable
base class should not be instantiated directly. It provides common functionality for Hoodoo::Presenters::Embedding::Embeds
and Hoodoo::Presenters::Embedding::References
- use those instead.
Public Class Methods
Create an instance.
# File lib/hoodoo/presenters/embedding.rb, line 29 def initialize @hash = {} end
Public Instance Methods
Add a collection of resources (for embedding) or UUIDs (for referencing) to an embed or reference assembly.
key
-
The key to use in the resource representation leading to the embedded resource object or
UUID
string array. Typically follows a plural name convention in your resource API field language of choice, e.g. “members” (an API where the resource names and fields are in English), “mitglieder” (an API described in German).This key must match the value specified in the query string of a request in order to ask for the things in question to be embedded / referenced.
array_of_rendered_resources_or_uuids
-
An
Array
of rendered resource representations in full, or anArray
of resourceUUID
Strings.
# File lib/hoodoo/presenters/embedding.rb, line 73 def add_many( key, array_of_rendered_resources_or_uuids ) validate_many( array_of_rendered_resources_or_uuids ) @hash[ key ] = array_of_rendered_resources_or_uuids end
Add a singlular resource (for embedding) or UUID
(for referencing) to an embed or reference assembly.
key
-
The key to use in the resource representation leading to the embedded resource object or
UUID
string. Typically follows a singular name convention in your resource API field language of choice, e.g. “member” (an API where the resource names and fields are in English), “mitglied” (an API described in German).This key must match the value specified in the query string of a request in order to ask for the thing in question to be embedded / referenced.
rendered_resource_or_uuid
-
A rendered resource representation in full, or a resource
UUID
String
.
# File lib/hoodoo/presenters/embedding.rb, line 50 def add_one( key, rendered_resource_or_uuid ) validate_one( rendered_resource_or_uuid ) @hash[ key ] = rendered_resource_or_uuid end
Delete all data associated with the given key.
key
-
As provided to a prior call to
add_one
oradd_many
. Has no side effects if the key has not been previously used in such a call; no error is raised in this case either.
# File lib/hoodoo/presenters/embedding.rb, line 84 def remove( key ) @hash.delete( key ) end
Returns a Hash
where keys are the keys provided in calls to add_one
or add_many
and values are the values provided to those same corresponding calls. Returns an empty Hash
if no such calls have been made or if all the keys were subsequently removed with remove
.
# File lib/hoodoo/presenters/embedding.rb, line 93 def retrieve @hash end