Class: ActionDispatch::Routing::RouteSet::Dispatcher

Inherits:
Endpoint show all
Defined in:
actionpack/lib/action_dispatch/routing/route_set.rb

Instance Method Summary collapse

Methods inherited from Endpoint

#app, #matches?, #redirect?

Constructor Details

#initialize(defaults) ⇒ Dispatcher

Returns a new instance of Dispatcher



24
25
26
27
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 24

def initialize(defaults)
  @defaults = defaults
  @controller_class_names = ThreadSafe::Cache.new
end

Instance Method Details

#controller(params, default_controller = true) ⇒ Object

If this is a default_controller (i.e. a controller specified by the user) we should raise an error in case it's not found, because it usually means a user error. However, if the controller was retrieved through a dynamic segment, as in :controller(/:action), we should simply return nil and delegate the control back to Rack cascade. Besides, if this is not a default controller, it means we should respect the @scope parameter.



56
57
58
59
60
61
62
63
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 56

def controller(params, default_controller=true)
  if params && params.key?(:controller)
    controller_param = params[:controller]
    controller_reference(controller_param)
  end
rescue NameError => e
  raise ActionController::RoutingError, e.message, e.backtrace if default_controller
end

#dispatcher?Boolean

Returns:

  • (Boolean)


29
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 29

def dispatcher?; true; end

#prepare_params!(params) ⇒ Object



45
46
47
48
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 45

def prepare_params!(params)
  normalize_controller!(params)
  merge_default_action!(params)
end

#serve(req) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 31

def serve(req)
  req.check_path_parameters!
  params = req.path_parameters

  prepare_params!(params)

  # Just raise undefined constant errors if a controller was specified as default.
  unless controller = controller(params, @defaults.key?(:controller))
    return [404, {'X-Cascade' => 'pass'}, []]
  end

  dispatch(controller, params[:action], req.env)
end