class Hanami::Routing::LazyEndpoint

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.

@since 0.1.0

@api private

@see Hanami::Routing::ClassEndpoint

Public Class Methods

new(name, namespace) click to toggle source

Initialize the lazy endpoint

@since 0.1.0 @api private

# File lib/hanami/routing/endpoint.rb, line 129
def initialize(name, namespace)
  @name, @namespace = name, namespace
end

Public Instance Methods

call(env) click to toggle source

Rack interface

@raise [EndpointNotFound] when the endpoint can't be found.

@since 0.1.0 @api private

# File lib/hanami/routing/endpoint.rb, line 139
def call(env)
  obj.call(env)
end
inspect() click to toggle source

@since 0.2.0 @api private

# 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

Private Instance Methods

klass() click to toggle source

@since 0.2.0 @api private

# File lib/hanami/routing/endpoint.rb, line 167
def klass
  Utils::Class.load!(@name, @namespace)
rescue NameError => e
  raise EndpointNotFound.new(e.message)
end
obj() click to toggle source

@since 0.1.0 @api private

# File lib/hanami/routing/endpoint.rb, line 161
def obj
  klass.new
end