Class: Hoodoo::Presenters::Embedding::Embeddable

Inherits:
Object
  • Object
show all
Defined in:
lib/hoodoo/presenters/embedding.rb

Overview

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.

Direct Known Subclasses

Embeds, References

Instance Method Summary collapse

Constructor Details

#initializeEmbeddable

Create an instance.



29
30
31
# File 'lib/hoodoo/presenters/embedding.rb', line 29

def initialize
  @hash = {}
end

Instance Method Details

#add_many(key, array_of_rendered_resources_or_uuids) ⇒ Object

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 an Array of resource UUID Strings.



73
74
75
76
# 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_one(key, rendered_resource_or_uuid) ⇒ Object

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.



50
51
52
53
# 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

#remove(key) ⇒ Object

Delete all data associated with the given key.

key

As provided to a prior call to #add_one or #add_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.



84
85
86
# File 'lib/hoodoo/presenters/embedding.rb', line 84

def remove( key )
  @hash.delete( key )
end

#retrieveObject

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.



93
94
95
# File 'lib/hoodoo/presenters/embedding.rb', line 93

def retrieve
  @hash
end