Class: Hanami::Routing::LazyEndpoint Private

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/hanami/routing/endpoint.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Routing endpoint This is the object that responds to an HTTP request made against a certain path.

The router will use this class for the same use cases of ‘ClassEndpoint`, but when the target class can’t be found, instead of raise a ‘LoadError` we reference in a lazy endpoint.

For each incoming HTTP request, it will look for the referenced class, then it will instantiate and invoke #call on the object.

This behavior is required to solve a chicken-egg situation when we try to load the router first and then the application with all its endpoints.

See Also:

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(name, namespace) ⇒ LazyEndpoint

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the lazy endpoint

Since:

  • 0.1.0



108
109
110
# File 'lib/hanami/routing/endpoint.rb', line 108

def initialize(name, namespace)
  @name, @namespace = name, namespace
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rack interface

Raises:

Since:

  • 0.1.0



117
118
119
# File 'lib/hanami/routing/endpoint.rb', line 117

def call(env)
  obj.call(env)
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/hanami/routing/endpoint.rb', line 122

def inspect
  # TODO review this implementation once the namespace feature will be
  # cleaned up.
  result = klass rescue nil

  if result.nil?
    result = @name
    result = "#{ @namespace }::#{ result }" if @namespace != Object
  end

  result
end