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

Methods inherited from Endpoint

#destination_path, #redirect?, #routable?

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



129
130
131
# File 'lib/hanami/routing/endpoint.rb', line 129

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



139
140
141
# File 'lib/hanami/routing/endpoint.rb', line 139

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



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/hanami/routing/endpoint.rb', line 145

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