Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Includes:
Base, Concerns, CustomUrls, HttpHelpers, Resources, Scoping, Redirection
Defined in:
actionpack/lib/action_dispatch/routing/mapper.rb

Defined Under Namespace

Modules: Base, Concerns, CustomUrls, HttpHelpers, Resources, Scoping Classes: Constraints, Mapping, Scope

Constant Summary collapse

URL_OPTIONS =
[:protocol, :subdomain, :domain, :host, :port]

Constants included from Resources

Resources::CANONICAL_ACTIONS, Resources::RESOURCE_OPTIONS, Resources::VALID_ON_OPTIONS

Constants included from Scoping

Scoping::POISON

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CustomUrls

#direct, #resolve

Methods included from Resources

#collection, #draw, #match, #member, #namespace, #nested, #new, #resource, #resources, #resources_path_names, #root, #shallow, #shallow?

Methods included from Concerns

#concern, #concerns

Methods included from Scoping

#constraints, #controller, #defaults, #namespace, #scope

Methods included from Redirection

#redirect

Methods included from HttpHelpers

#delete, #get, #options, #patch, #post, #put

Methods included from Base

#default_url_options=, #has_named_route?, #match, #mount, #with_default_scope

Constructor Details

#initialize(set) ⇒ Mapper

:nodoc:



2313
2314
2315
2316
2317
2318
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 2313

def initialize(set) #:nodoc:
  @set = set
  @draw_paths = set.draw_paths
  @scope = Scope.new(path_names: @set.resources_path_names)
  @concerns = {}
end

Class Method Details

.normalize_name(name) ⇒ Object



421
422
423
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 421

def self.normalize_name(name)
  normalize_path(name)[1..-1].tr("/", "_")
end

.normalize_path(path) ⇒ Object

Invokes Journey::Router::Utils.normalize_path, then ensures that /(:locale) becomes (/:locale). Except for root cases, where the former is the correct one.



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 404

def self.normalize_path(path)
  path = Journey::Router::Utils.normalize_path(path)

  # the path for a root URL at this point can be something like
  # "/(/:locale)(/:platform)/(:browser)", and we would want
  # "/(:locale)(/:platform)(/:browser)"

  # reverse "/(", "/((" etc to "(/", "((/" etc
  path.gsub!(%r{/(\(+)/?}, '\1/')
  # if a path is all optional segments, change the leading "(/" back to
  # "/(" so it evaluates to "/" when interpreted with no options.
  # Unless, however, at least one secondary segment consists of a static
  # part, ex. "(/:locale)(/pages/:page)"
  path.sub!(%r{^(\(+)/}, '/\1') if %r{^(\(+[^)]+\))(\(+/:[^)]+\))*$}.match?(path)
  path
end