Class: Gaffe::ErrorsControllerResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/gaffe/errors_controller_resolver.rb

Constant Summary collapse

BUILTIN_CONTROLLER =

Constants

lambda do
  require 'gaffe/errors_controller'
  Gaffe::ErrorsController
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ ErrorsControllerResolver

Returns a new instance of ErrorsControllerResolver.



12
13
14
# File 'lib/gaffe/errors_controller_resolver.rb', line 12

def initialize(env)
  @env = env
end

Instance Attribute Details

#controllerObject (readonly)

Accessors



4
5
6
# File 'lib/gaffe/errors_controller_resolver.rb', line 4

def controller
  @controller
end

Instance Method Details

#resolved_controllerObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gaffe/errors_controller_resolver.rb', line 16

def resolved_controller
  # Use the configured controller first
  controller = Gaffe.configuration.errors_controller

  # Parse the request if multiple controllers are configured
  controller = request_controller(controller) if controller.is_a?(Hash)

  # Fall back on the builtin errors controller
  controller ||= BUILTIN_CONTROLLER.call

  # Make sure we return a Class
  controller.respond_to?(:constantize) ? controller.constantize : controller
end