Class: Webpacker::FileLoader
- Inherits:
-
Object
- Object
- Webpacker::FileLoader
- Defined in:
- lib/webpacker/file_loader.rb
Overview
Provides a base singleton-configuration pattern for loading a file, given a path
Direct Known Subclasses
Defined Under Namespace
Classes: FileLoaderError, NotFoundError
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/webpacker/file_loader.rb', line 7 def data @data end |
#mtime ⇒ Object
Returns the value of attribute mtime.
7 8 9 |
# File 'lib/webpacker/file_loader.rb', line 7 def mtime @mtime end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/webpacker/file_loader.rb', line 7 def path @path end |
Class Method Details
.file_path ⇒ Object
20 21 22 |
# File 'lib/webpacker/file_loader.rb', line 20 def file_path raise FileLoaderError.new("Subclass of Webpacker::FileLoader should override this method") end |
.load_instance(path = file_path) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/webpacker/file_loader.rb', line 10 def load_instance(path = file_path) # Assume production is 100% cached and don't reload if file's mtime not changed cached = self.instance && # if we have a singleton (env == "production" || # skip if production bc always cached (File.exist?(path) && self.instance.mtime == File.mtime(path))) # skip if mtime not changed return if cached self.instance = new(path) end |
.reset ⇒ Object
24 25 26 27 |
# File 'lib/webpacker/file_loader.rb', line 24 def reset self.instance = nil load_instance end |