class Hoodoo::Presenters::Embedding::References

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):

Simple example:

references = Hoodoo::Presenters::Embedding::References.new
references.add_one( 'member', member_uuid )
references.add_many( 'memberships', array_of_membership_uuids )

Public Instance Methods

resource_key() click to toggle source

Returns the top-level resource key used for reference data, as per the API documentation - which is the String _reference.

# File lib/hoodoo/presenters/embedding.rb, line 194
def resource_key
  '_reference'
end

Protected Instance Methods

validate_many( thing ) click to toggle source

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.

# 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
validate_one( thing ) click to toggle source

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.

# 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