class Sprockets::Base

‘Base` class for `Environment` and `Cached`.

def [](*args)


environment['application.js']

Preferred `find_asset` shorthand.
def [](*args)
  find_asset(*args)
end

def cache=(cache)

`[key]`/`[key]=value`, `read(key)`/`write(key, value)`.
setters. Either `get(key)`/`set(key, value)`,
The cache store must implement a pair of getters and

Set persistent cache store
def cache=(cache)
  @cache = Cache.new(cache, logger)
end

def cache_get(key)

def cache_get(key)
  cache.get(key)
end

def cache_set(key, value)

def cache_set(key, value)
  cache.set(key, value)
end

def cached

Return an `Cached`. Must be implemented by the subclass.
def cached
  raise NotImplementedError
end

def each_logical_path(*args, &block)

Returns Enumerator if no block is given.

args - List of matcher objects.

Remove from 4.x.

Deprecated: Iterate over all logical paths with a matcher.
def each_logical_path(*args, &block)
  return to_enum(__method__, *args) unless block_given?
  filters = args.flatten.map { |arg| Manifest.compile_match_filter(arg) }
  logical_paths.each do |a, b|
    if filters.any? { |f| f.call(a, b) }
      if block.arity == 2
        yield a, b
      else
        yield a
      end
    end
  end
  nil
end

def file_digest(path)

Returns a String digest or nil.

path - String filename or directory path.

Internal: Compute digest for path.
def file_digest(path)
  if stat = self.stat(path)
    # Caveat: Digests are cached by the path's current mtime. Its possible
    # for a files contents to have changed and its mtime to have been
    # negligently reset thus appearing as if the file hasn't changed on
    # disk. Also, the mtime is only read to the nearest second. Its
    # also possible the file was updated more than once in a given second.
    cache.fetch("file_digest:#{path}:#{stat.mtime.to_i}") do
      self.stat_digest(path, stat)
    end
  end
end

def find_all_linked_assets(path, options = {})

def find_all_linked_assets(path, options = {})
  return to_enum(__method__, path, options) unless block_given?
  asset = find_asset(path, options)
  return unless asset
  yield asset
  stack = asset.links.to_a
  while uri = stack.shift
    yield asset = load(uri)
    stack = asset.links.to_a + stack
  end
  nil
end

def find_asset(path, options = {})

Find asset by logical path or expanded path.
def find_asset(path, options = {})
  uri, _ = resolve(path, options.merge(compat: false))
  if uri
    load(uri)
  end
end

def inspect

Pretty inspect
def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} " +
    "root=#{root.to_s.inspect}, " +
    "paths=#{paths.inspect}>"
end

def logical_paths

Returns an Enumerator of [logical_path, filename].

Deprecated: Enumerate over all logical paths in the environment.
def logical_paths
  return to_enum(__method__) unless block_given?
  seen = Set.new
  paths.each do |load_path|
    stat_tree(load_path).each do |filename, stat|
      next unless stat.file?
      path = split_subpath(load_path, filename)
      path, mime_type, _, _ = parse_path_extnames(path)
      path = normalize_logical_path(path)
      path += mime_types[mime_type][:extensions].first if mime_type
      if !seen.include?(path)
        yield path, filename
        seen << path
      end
    end
  end
  nil
end

def matches_filter(filters, logical_path, filename)

Deprecated: Seriously.
def matches_filter(filters, logical_path, filename)
  return true if filters.empty?
  filters.any? do |filter|
    if filter.is_a?(Regexp)
      filter.match(logical_path)
    elsif filter.respond_to?(:call)
      if filter.arity == 1
        filter.call(logical_path)
      else
        filter.call(logical_path, filename.to_s)
      end
    else
      File.fnmatch(filter.to_s, logical_path)
    end
  end
end

def resolve_with_compat(path, options = {})


# ]
# #
# "file:///path/to/app/javascripts/foo.js?type=application/javascript"
# => [
resolve("foo.js")

4.x

# ]
# #
# "file:///path/to/app/javascripts/foo.js?type=application/javascript"
# => [
resolve("foo.js", compat: false)

# => "/path/to/app/javascripts/foo.js"
resolve("foo.js", compat: true)

# => "/path/to/app/javascripts/foo.js"
resolve("foo.js")

3.x

# => "/path/to/app/javascripts/foo.js"
resolve("foo.js")

2.x

result.
and a set of file system dependencies that had to be read to compute the
compatible plain filename String. 4.x will always return an Asset URI
Deprecated: Change default return type of resolve() to return 2.x
def resolve_with_compat(path, options = {})
  options = options.dup
  if options.delete(:compat) { true }
    uri, _ = resolve_without_compat(path, options)
    if uri
      path, _ = parse_asset_uri(uri)
      path
    else
      nil
    end
  else
    resolve_without_compat(path, options)
  end
end

def unescape(str)

def unescape(str)
  str = URI::DEFAULT_PARSER.unescape(str)
  str.force_encoding(Encoding.default_internal) if Encoding.default_internal
  str
end

def unescape(str)

def unescape(str)
  URI.unescape(str)
end