Class: Journey::Router::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/journey/router/utils.rb

Defined Under Namespace

Modules: UriEscape

Constant Summary

Parser =
URI.const_defined?(:Parser) ? URI::Parser.new : URI

Class Method Summary (collapse)

Class Method Details

+ (Object) escape_fragment(fragment)



48
49
50
# File 'lib/journey/router/utils.rb', line 48

def self.escape_fragment(fragment)
  Parser.escape(fragment.to_s, UriEscape::UNSAFE_FRAGMENT)
end

+ (Object) escape_path(path)



44
45
46
# File 'lib/journey/router/utils.rb', line 44

def self.escape_path(path)
  Parser.escape(path.to_s, UriEscape::UNSAFE_SEGMENT)
end

+ (Object) normalize_path(path)

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

+ (Object) unescape_uri(uri)



52
53
54
# File 'lib/journey/router/utils.rb', line 52

def self.unescape_uri(uri)
  Parser.unescape(uri)
end