Method: Journey::Router::Utils.normalize_path

Defined in:
lib/journey/router/utils.rb

.normalize_path(path) ⇒ Object

Normalizes URI path.

Strips off trailing slash and ensures there is a leading slash.

normalize_path("/foo")  # => "/foo"
normalize_path("/foo/") # => "/foo"
normalize_path("foo")   # => "/foo"
normalize_path("")      # => "/"


14
15
16
17
18
19
20
# File 'lib/journey/router/utils.rb', line 14

def self.normalize_path(path)
  path = "/#{path}"
  path.squeeze!('/')
  path.sub!(%r{/+\Z}, '')
  path = '/' if path == ''
  path
end