Sha256: fd7427e669f9344f1bd3964d4202a3a37c323589aa002ca9c9c5e2abe4213d34

Contents?: true

Size: 742 Bytes

Versions: 13

Compression:

Stored size: 742 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

  def pwd(*path_parts)

    root_folder =if ENV['BUNDLE_GEMFILE']
                   ENV['BUNDLE_GEMFILE'].split(File::Separator)[0..-2].join(File::Separator)
                 else
                   Dir.pwd.to_s
                 end

    return File.join(root_folder,*path_parts)

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rack-app-0.15.0 lib/rack/app/utils.rb
rack-app-0.14.0 lib/rack/app/utils.rb
rack-app-0.13.0 lib/rack/app/utils.rb
rack-app-0.12.1 lib/rack/app/utils.rb
rack-app-0.12.0 lib/rack/app/utils.rb
rack-app-0.11.0 lib/rack/app/utils.rb
rack-app-0.10.1 lib/rack/app/utils.rb
rack-app-0.9.2 lib/rack/app/utils.rb
rack-app-0.9.1 lib/rack/app/utils.rb
rack-app-0.9.0 lib/rack/app/utils.rb
rack-app-0.8.2 lib/rack/app/utils.rb
rack-app-0.8.1 lib/rack/app/utils.rb
rack-app-0.7.0 lib/rack/app/utils.rb