class Sprockets::URITar

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/sprockets/uri_tar.rbs

class Sprockets::URITar
  def absolute_path?: () -> true
  def initialize: (String uri, Sprockets::CachedEnvironment env) -> void
end

Internal: used to “expand” and “compress” values for storage

def absolute_path?

Experimental RBS support (using type sampling data from the type_fusion project).

def absolute_path?: () -> true

This signature was generated using 1 sample from 1 application.

like C:/Schneems.
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

Returns String

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

Returns String

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

Returns String

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)

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (String uri, Sprockets::CachedEnvironment env) -> void

This signature was generated using 1 sample from 1 application.

env - The current "environment" that assets are being loaded into.
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