Class: Webpacker::Digests

Inherits:
Object
  • Object
show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Digests

Returns a new instance of Digests.



22
23
24
25
# File 'lib/webpacker/digests.rb', line 22

def initialize(path)
  @path = path
  load
end

Class Method Details

.load(path) ⇒ Object



9
10
11
# File 'lib/webpacker/digests.rb', line 9

def load(path)
  self.instance = new(path)
end

.lookup(name) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/webpacker/digests.rb', line 13

def lookup(name)
  if instance
    instance.lookup(name)
  else
    raise "Webpacker::Digests.load(path) must be called first"
  end
end

Instance Method Details

#lookup(name) ⇒ Object



27
28
29
# File 'lib/webpacker/digests.rb', line 27

def lookup(name)
  @digests[name.to_s]
end