Sha256: 435b620dddfed2a1df8669b1cecdab27b88157de54c2b3a60814a8e8b596b00f

Contents?: true

Size: 453 Bytes

Versions: 4

Compression:

Stored size: 453 Bytes

Contents

module Rack::App::Utils
  extend self

  # 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("")      # => "/"
  def normalize_path(path)
    path = "/#{path}"
    path.squeeze!('/')
    path.sub!(%r{/+\Z}, '')
    path = '/' if path == ''
    path
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rack-app-0.6.0 lib/rack/app/utils.rb
rack-app-0.5.0 lib/rack/app/utils.rb
rack-app-0.4.0 lib/rack/app/utils.rb
rack-app-0.3.0 lib/rack/app/utils.rb