Class: ActionDispatch::Routing::RouteSet::Generator
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::RouteSet::Generator
- Defined in:
- actionpack/lib/action_dispatch/routing/route_set.rb
Overview
:nodoc:
Instance Attribute Summary (collapse)
-
- (Object) named_route
readonly
Returns the value of attribute named_route.
-
- (Object) options
readonly
Returns the value of attribute options.
-
- (Object) recall
readonly
Returns the value of attribute recall.
-
- (Object) script_name
readonly
Returns the value of attribute script_name.
-
- (Object) set
readonly
Returns the value of attribute set.
Instance Method Summary (collapse)
- - (Object) controller
- - (Object) current_controller
- - (Boolean) different_controller?
- - (Object) generate
-
- (Object) handle_nil_action!
This handles the case of :action => nil being explicitly passed.
-
- (Generator) initialize(options, recall, set, extras = false)
constructor
A new instance of Generator.
-
- (Object) normalize_controller_action_id!
This pulls :controller, :action, and :id out of the recall.
- - (Object) normalize_options!
- - (Object) opts
- - (Object) raise_routing_error
- - (Object) use_recall_for(key)
-
- (Object) use_relative_controller!
if the current controller is "foo/bar/baz" and :controller => "baz/bat" is specified, the controller becomes "foo/baz/bat".
Constructor Details
- (Generator) initialize(options, recall, set, extras = false)
A new instance of Generator
308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 308 def initialize(, recall, set, extras = false) @script_name = .delete(:script_name) @named_route = .delete(:use_route) @options = .dup @recall = recall.dup @set = set @extras = extras normalize_controller_action_id! use_relative_controller! controller.sub!(%r{^/}, '') if controller handle_nil_action! end |
Instance Attribute Details
- (Object) named_route (readonly)
Returns the value of attribute named_route
306 307 308 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 306 def named_route @named_route end |
- (Object) options (readonly)
Returns the value of attribute options
306 307 308 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 306 def @options end |
- (Object) recall (readonly)
Returns the value of attribute recall
306 307 308 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 306 def recall @recall end |
- (Object) script_name (readonly)
Returns the value of attribute script_name
306 307 308 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 306 def script_name @script_name end |
- (Object) set (readonly)
Returns the value of attribute set
306 307 308 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 306 def set @set end |
Instance Method Details
- (Object) controller
323 324 325 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 323 def controller @controller ||= @options[:controller] end |
- (Object) current_controller
327 328 329 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 327 def current_controller @recall[:controller] end |
- (Boolean) different_controller?
427 428 429 430 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 427 def different_controller? return false unless current_controller controller.to_param != current_controller.to_param end |
- (Object) generate
394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 394 def generate path, params = @set.set.generate(:path_info, named_route, , recall, opts) raise_routing_error unless path params.reject! {|k,v| !v } return [path, params.keys] if @extras path << "?#{params.to_query}" if params.any? "#{script_name}#{path}" rescue Rack::Mount::RoutingError raise_routing_error end |
- (Object) handle_nil_action!
This handles the case of :action => nil being explicitly passed. It is identical to :action => "index"
387 388 389 390 391 392 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 387 def handle_nil_action! if .has_key?(:action) && [:action].nil? [:action] = 'index' end recall[:action] = .delete(:action) if [:action] == 'index' end |
- (Object) normalize_controller_action_id!
This pulls :controller, :action, and :id out of the recall. The recall key is only used if there is no key in the options or if the key in the options is identical. If any of :controller, :action or :id is not found, don't pull any more keys from the recall.
366 367 368 369 370 371 372 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 366 def normalize_controller_action_id! @recall[:action] ||= 'index' if current_controller use_recall_for(:controller) or return use_recall_for(:action) or return use_recall_for(:id) end |
- (Object) normalize_options!
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 341 def # If an explicit :controller was given, always make :action explicit # too, so that action expiry works as expected for things like # # generate({:controller => 'content'}, {:controller => 'content', :action => 'show'}) # # (the above is from the unit tests). In the above case, because the # controller was explicitly given, but no action, the action is implied to # be "index", not the recalled action of "show". if [:controller] [:action] ||= 'index' [:controller] = [:controller].to_s end if [:action] [:action] = [:action].to_s end end |
- (Object) opts
409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 409 def opts parameterize = lambda do |name, value| if name == :controller value elsif value.is_a?(Array) value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') else return nil unless param = value.to_param param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") end end {:parameterize => parameterize} end |
- (Object) raise_routing_error
423 424 425 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 423 def raise_routing_error raise ActionController::RoutingError.new("No route matches #{.inspect}") end |
- (Object) use_recall_for(key)
331 332 333 334 335 336 337 338 339 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 331 def use_recall_for(key) if @recall[key] && (!@options.key?(key) || @options[key] == @recall[key]) if named_route_exists? @options[key] = @recall.delete(key) if segment_keys.include?(key) else @options[key] = @recall.delete(key) end end end |
- (Object) use_relative_controller!
if the current controller is "foo/bar/baz" and :controller => "baz/bat" is specified, the controller becomes "foo/baz/bat"
376 377 378 379 380 381 382 383 |
# File 'actionpack/lib/action_dispatch/routing/route_set.rb', line 376 def use_relative_controller! if !named_route && different_controller? old_parts = current_controller.split('/') size = controller.count("/") + 1 parts = old_parts[0...-size] << controller @controller = @options[:controller] = parts.join("/") end end |