class Sprockets::URITar
Internal: used to “expand” and “compress” values for storage
def absolute_path?
Windows systems start with a drive letter than colon and slash
Nix* systems start with a `/` like /Users/schneems.
Internal: Tells us if we are using an absolute path
def absolute_path? PathUtils.absolute_path?(path) end
def compress
uri will be returned.
If a uri is outside of the environment's root the original
be shortened to be a relative path.
If a uri is inside of an environment's root it will
Internal: Converts full uri to a "compressed" uri
def compress scheme + compressed_path end
def compressed_path
Only path information is returned, and not scheme.
Otherwise an absolute path will be returned.
it will return a path relative to the environment root.
If the input uri is relative to the environment root
Internal: Returns "compressed" path
def compressed_path # windows if !@root.start_with?("/".freeze) && path.start_with?("/".freeze) consistent_root = "/".freeze + @root else consistent_root = @root end if compressed_path = PathUtils.split_subpath(consistent_root, path) compressed_path else path end end
def expand
file:///This/is/an/absolute/path
If a uri is outside the root, it will start with a slash:
file://this/is/a/relative/path
start with a slash for example:
If a uri is inside of the environment's root it will not
Internal: Convert a "compressed" uri to an absolute path
def expand if absolute_path? # Stored path was absolute, don't add root scheme + path else if scheme.empty? File.join(root, path) else # We always want to return an absolute uri, # make sure the path starts with a slash. scheme + File.join("/".freeze, root, path) end end end
def initialize(uri, env)
uri - A String containing URI that may or may not contain the scheme
Internal: Initialize object for compression or expansion
def initialize(uri, env) @root = env.root @env = env uri = uri.to_s if uri.include?("://".freeze) @scheme, _, @path = uri.partition("://".freeze) @scheme << "://".freeze else @scheme = "".freeze @path = uri end end