Class: Webpacker::Digests
- Inherits:
-
Object
- Object
- Webpacker::Digests
- Defined in:
- lib/webpacker/digests.rb
Overview
Singleton registry for accessing the digested filenames computed by Webpack in production mode. This allows javascript_pack_tag to take a reference to, say, “calendar.js” and turn it into “calendar-1016838bab065ae1e314.js”. These digested filenames are what enables you to long-term cache things in production.
Defined Under Namespace
Classes: DigestError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Digests
constructor
A new instance of Digests.
- #lookup(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ Digests
Returns a new instance of Digests.
24 25 26 27 |
# File 'lib/webpacker/digests.rb', line 24 def initialize(path) @path = path @digests = load end |
Class Method Details
.load(path) ⇒ Object
11 12 13 |
# File 'lib/webpacker/digests.rb', line 11 def load(path) self.instance = new(path) end |
.lookup(name) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/webpacker/digests.rb', line 15 def lookup(name) if instance instance.lookup(name).presence || raise(DigestError.new("Can't find #{name} in #{instance.inspect}")) else raise DigestError.new("Webpacker::Digests.load(path) must be called first") end end |
Instance Method Details
#lookup(name) ⇒ Object
29 30 31 |
# File 'lib/webpacker/digests.rb', line 29 def lookup(name) @digests[name.to_s] end |