Class Sprockets::Base
In: lib/sprockets/base.rb
Parent: Object

`Base` class for `Environment` and `Index`.

Methods

Included Modules

Caching Processing Server Trail

Attributes

cache  [R]  Get persistent cache store
context_class  [R]  Get `Context` class.

This class maybe mutated and mixed in with custom helpers.

    environment.context_class.instance_eval do
      include MyHelpers
      def asset_url; end
    end
digest_class  [R]  Returns a `Digest` implementation class.

Defaults to `Digest::MD5`.

logger  [RW]  Get and set `Logger` instance.
version  [R]  The `Environment#version` is a custom value used for manually expiring all asset caches.

Sprockets is able to track most file and directory changes and will take care of expiring the cache for you. However, its impossible to know when any custom helpers change that you mix into the `Context`.

It would be wise to increment this value anytime you make a configuration change to the `Environment` object.

Public Instance methods

Preferred `find_asset` shorthand.

    environment['application.js']

Internal. Return a `AssetAttributes` for `path`.

Set persistent cache store

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

Internal. Return content type of `path`.

Returns a `Digest` instance for the `Environment`.

This value serves two purposes. If two `Environment`s have the same digest value they can be treated as equal. This is more useful for comparing environment states between processes rather than in the same. Two equal `Environment`s can share the same cached assets.

The value also provides a seed digest for all `Asset` digests. Any change in the environment digest will affect all of its assets.

Assign a `Digest` implementation class. This maybe any Ruby `Digest::` implementation such as `Digest::MD5` or `Digest::SHA1`.

    environment.digest_class = Digest::SHA1

Works like `Dir.entries`.

Subclasses may cache this method.

Read and compute digest of filename.

Subclasses may cache this method.

Find asset by logical path or expanded path.

Return an `Index`. Must be implemented by the subclass.

Works like `File.stat`.

Subclasses may cache this method.

Assign an environment version.

    environment.version = '2.0'

Protected Instance methods

Clear index after mutating state. Must be implemented by the subclass.

[Validate]