Class: Sprockets::URITar

### Home Classes Methods

### In Files

- lib/sprockets/uri_tar.rb

### Parent

Object

### Methods

- ::new
- #absolute_path?
- #compress
- #compressed_path
- #expand

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::Autoload
- Sprockets::Base
- Sprockets::Bower
- Sprockets::Bundle
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Cache::GetWrapper
- Sprockets::Cache::HashWrapper
- Sprockets::Cache::MemoryStore
- Sprockets::Cache::NullStore
- Sprockets::Cache::ReadWriteWrapper
- Sprockets::Cache::Wrapper
- Sprockets::CachedEnvironment
- Sprockets::ClosureCompressor
- Sprockets::CoffeeScriptProcessor
- Sprockets::CoffeeScriptTemplate
- Sprockets::Compressing
- Sprockets::Configuration
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::ConversionError
- Sprockets::Dependencies
- Sprockets::DigestUtils
- Sprockets::DirectiveProcessor
- Sprockets::ERBProcessor
- Sprockets::ERBTemplate
- Sprockets::EcoProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsProcessor
- Sprockets::EjsTemplate
- Sprockets::EncodingUtils
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::FileReader
- Sprockets::HTTPUtils
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::LegacyProcProcessor
- Sprockets::LegacyTiltProcessor
- Sprockets::Loader
- Sprockets::Manifest
- Sprockets::ManifestUtils
- Sprockets::Mime
- Sprockets::NotFound
- Sprockets::NotImplementedError
- Sprockets::PathDependencyUtils
- Sprockets::PathDigestUtils
- Sprockets::PathUtils
- Sprockets::Paths
- Sprockets::Processing
- Sprockets::ProcessorUtils
- Sprockets::Resolve
- Sprockets::SassCompressor
- Sprockets::SassProcessor
- Sprockets::SassProcessor::CacheStore
- Sprockets::SassProcessor::Functions
- Sprockets::SassTemplate
- Sprockets::ScssProcessor
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::Transformers
- Sprockets::URITar
- Sprockets::URIUtils
- Sprockets::UglifierCompressor
- Sprockets::UnloadedAsset
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::URITar

Internal: used to "expand" and "compress" values for storage

### Attributes

path[R]
root[R]
scheme[R]

### Public Class Methods

new(uri, env) click to toggle source

Internal: Initialize object for compression or expansion

uri - A String containing URI that may or may not contain the scheme env - The current "environment" that assets are being loaded into.

    # File lib/sprockets/uri_tar.rb, line 12
    def initialize(uri, env)
      @root = env.root
      @env  = env
      uri   = uri.to_s
      if uri.include?("://".freeze)
        uri_array = uri.split("://".freeze)
        @scheme   = uri_array.shift
        @scheme   << "://".freeze
        @path     = uri_array.join("".freeze)
      else
        @scheme = "".freeze
        @path   = uri
      end
    end

### Public Instance Methods

absolute_path?() click to toggle source

Internal: Tells us if we are using an absolute path

Nix* systems start with a `/` like /Users/schneems. Windows systems start with a drive letter than colon and slash like C:/Schneems.

    # File lib/sprockets/uri_tar.rb, line 45
    def absolute_path?
      PathUtils.absolute_path?(path)
    end

compress() click to toggle source

Internal: Converts full uri to a "compressed" uri

If a uri is inside of an environment's root it will be shortened to be a relative path.

If a uri is outside of the environment's root the original uri will be returned.

Returns String

    # File lib/sprockets/uri_tar.rb, line 36
    def compress
      scheme + compressed_path
    end

compressed_path() click to toggle source

Internal: Returns "compressed" path

If the input uri is relative to the environment root it will return a path relative to the environment root. Otherwise an absolute path will be returned.

Only path information is returned, and not scheme.

Returns String

    # File lib/sprockets/uri_tar.rb, line 85
    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

expand() click to toggle source

Internal: Convert a "compressed" uri to an absolute path

If a uri is inside of the environment's root it will not start with a slash for example:

    file://this/is/a/relative/path

If a uri is outside the root, it will start with a slash:

    file:///This/is/an/absolute/path

Returns String

    # File lib/sprockets/uri_tar.rb, line 61
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.