Class: Restspec::Stores::EndpointStoreDelegator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/restspec/stores/endpoint_store.rb

Overview

Provides methods for the EndpointStore object.

Instance Method Summary collapse

Instance Method Details

#get(endpoint_name) ⇒ Restspec::Endpoints::Endpoint?

Get is just an alias for Hash#[]

Returns:


18
19
20
# File 'lib/restspec/stores/endpoint_store.rb', line 18

def get(endpoint_name)
  self[endpoint_name]
end

#get_by_schema_name_and_role(schema_name, endpoint_name, role) ⇒ Restspec::Endpoints::Endpoint?

Get an endpoint by the schema, name and a role.

Examples:

# Let's assume in the store there are 3 endpoints
# called :show, in different namespaces.

Restspec::EndpointStore.get_by_schema_name_and_role(:book, :show, :response)
# => this will only return the one whose schema is :book and are suitable for response.

Returns:


32
33
34
35
36
# File 'lib/restspec/stores/endpoint_store.rb', line 32

def get_by_schema_name_and_role(schema_name, endpoint_name, role)
  values.find do |endpoint|
    endpoint.name == endpoint_name && endpoint.schema_for(role).try(:name) == schema_name
  end
end

#store(endpoint) ⇒ Restspec::Endpoints::Endpoint

Stores an endpoint. It uses the full_name method of the endpoint to use as the key for the endpoint itself.

Parameters:

Returns:


12
13
14
# File 'lib/restspec/stores/endpoint_store.rb', line 12

def store(endpoint)
  self[endpoint.full_name] = endpoint
end