Class: Hanami::Router::RecognizedRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/router/recognized_route.rb

Overview

Represents a result of router path recognition.

See Also:

Since:

  • 0.5.0

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, env) ⇒ RecognizedRoute

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.

Returns a new instance of RecognizedRoute.

Since:

  • 0.5.0



14
15
16
17
# File 'lib/hanami/router/recognized_route.rb', line 14

def initialize(endpoint, env)
  @endpoint = endpoint
  @env = env
end

Instance Method Details

#call(env) ⇒ Array

Rack protocol compatibility

Parameters:

  • env (Hash)

    Rack env

Returns:

  • (Array)

    serialized Rack response

Raises:

See Also:

Since:

  • 0.5.0



32
33
34
35
36
37
38
# File 'lib/hanami/router/recognized_route.rb', line 32

def call(env)
  if routable?
    @endpoint.call(env)
  else
    raise NotRoutableEndpointError.new(@env)
  end
end

#endpointObject?

Returns the route’s endpoint object.

Returns nil if the route is a redirect.

Returns:

  • (Object, nil)

Since:

  • 0.7.0



78
79
80
81
82
# File 'lib/hanami/router/recognized_route.rb', line 78

def endpoint
  return nil if redirect?

  @endpoint
end

#paramsHash

Returns the route’s path params.

Returns:

  • (Hash)

Since:

  • 0.7.0



66
67
68
# File 'lib/hanami/router/recognized_route.rb', line 66

def params
  @env[Router::PARAMS]
end

#pathString

Relative URL (path)

Returns:

  • (String)

Since:

  • 0.7.0



56
57
58
# File 'lib/hanami/router/recognized_route.rb', line 56

def path
  @env[::Rack::PATH_INFO]
end

#redirect?Boolean

Returns true if the route is a redirect.

Returns:

  • (Boolean)

Since:

  • 0.7.0



100
101
102
# File 'lib/hanami/router/recognized_route.rb', line 100

def redirect?
  @endpoint.is_a?(Redirect)
end

#redirection_pathString?

Returns the route’s redirect path, if it is a redirect, or nil otherwise.

Returns:

  • (String, nil)

Since:

  • 0.7.0



110
111
112
113
114
# File 'lib/hanami/router/recognized_route.rb', line 110

def redirection_path
  return nil unless redirect?

  @endpoint.destination
end

#routable?Boolean

Returns true if the route has an #endpoint.

Returns:

  • (Boolean)

Since:

  • 0.7.0



90
91
92
# File 'lib/hanami/router/recognized_route.rb', line 90

def routable?
  !@endpoint.nil?
end

#verbString

HTTP verb (aka method)

Returns:

  • (String)

Since:

  • 0.5.0



46
47
48
# File 'lib/hanami/router/recognized_route.rb', line 46

def verb
  @env[::Rack::REQUEST_METHOD]
end