Module: Sprockets::Digest

Included in:
Base
Defined in:
lib/sprockets/digest.rb

Overview

‘Digest` is an internal mixin whose public methods are exposed on the `Environment` and `Index` classes.

Instance Method Summary collapse

Instance Method Details

#digestObject

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.



57
58
59
60
61
62
63
64
65
# File 'lib/sprockets/digest.rb', line 57

def digest
  # Compute the initial digest using the implementation class. The
  # Sprockets release version and custom environment version are
  # mixed in. So any new releases will affect all your assets.
  @digest ||= digest_class.new.update(VERSION).update(version.to_s)

  # Returned a dupped copy so the caller can safely mutate it with `.update`
  @digest.dup
end

#digest_classObject

Returns a ‘Digest` implementation class.

Defaults to ‘Digest::MD5`.



8
9
10
# File 'lib/sprockets/digest.rb', line 8

def digest_class
  @digest_class
end

#digest_class=(klass) ⇒ Object

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

environment.digest_class = Digest::SHA1


18
19
20
21
# File 'lib/sprockets/digest.rb', line 18

def digest_class=(klass)
  expire_index!
  @digest_class = klass
end

#versionObject

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.



33
34
35
# File 'lib/sprockets/digest.rb', line 33

def version
  @version
end

#version=(version) ⇒ Object

Assign an environment version.

environment.version = '2.0'


41
42
43
44
# File 'lib/sprockets/digest.rb', line 41

def version=(version)
  expire_index!
  @version = version
end