Class: ActionDispatch::Routing::RouteSet::Dispatcher
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::RouteSet::Dispatcher
- Defined in:
- lib/action_dispatch/routing/route_set.rb
Overview
:nodoc:
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#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.
-
#initialize(options = {}) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
- #prepare_params!(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Dispatcher
Returns a new instance of Dispatcher.
21 22 23 24 25 |
# File 'lib/action_dispatch/routing/route_set.rb', line 21 def initialize(={}) @defaults = [:defaults] @glob_param = .delete(:glob) @controllers = {} end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/action_dispatch/routing/route_set.rb', line 27 def call(env) params = env[PARAMETERS_KEY] 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], env) end |
#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.
51 52 53 54 55 56 57 58 |
# File 'lib/action_dispatch/routing/route_set.rb', line 51 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., e.backtrace if default_controller end |
#prepare_params!(params) ⇒ Object
39 40 41 42 43 |
# File 'lib/action_dispatch/routing/route_set.rb', line 39 def prepare_params!(params) normalize_controller!(params) merge_default_action!(params) split_glob_param!(params) if @glob_param end |