Class: Racket::Utils::Routing::Dispatcher
- Inherits:
-
Object
- Object
- Racket::Utils::Routing::Dispatcher
- Defined in:
- lib/racket/utils/routing.rb
Overview
Class responsible for dispatching requests to controllers.
Class Method Summary collapse
-
.extract_target(response) ⇒ Array
Extracts the target class, target params and target action from a list of valid routes.
Instance Method Summary collapse
-
#dispatch ⇒ Array
Dispatches request to a controller.
-
#initialize(env, target_info) ⇒ Dispatcher
constructor
Constructor.
Constructor Details
#initialize(env, target_info) ⇒ Dispatcher
Constructor
103 104 105 106 |
# File 'lib/racket/utils/routing.rb', line 103 def initialize(env, target_info) @env = env @controller_class, @params, @action = target_info end |
Class Method Details
.extract_target(response) ⇒ Array
Extracts the target class, target params and target action from a list of valid routes.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/racket/utils/routing.rb', line 87 def self.extract_target(response) target_klass = response.route.dest params = response.param_values.first.reject(&:empty?) action = if params.empty? target_klass.settings.fetch(:default_action) else params.shift.to_sym end [target_klass, params, action] end |
Instance Method Details
#dispatch ⇒ Array
Dispatches request to a controller. This is the default action whenever a matching route for a request is found.
112 113 114 115 116 117 118 |
# File 'lib/racket/utils/routing.rb', line 112 def dispatch # Rewrite PATH_INFO to reflect that we split out the parameters update_path_info(@params.length) # Call controller call_controller(Current.init(RouterParams.new(@action, @params, @env))) end |