Class: WebpackerLite::FileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/webpacker_lite/file_loader.rb

Overview

Provides a base singleton-configuration pattern for loading a JSON or YAML file, given a path

Direct Known Subclasses

Configuration, Env, Manifest

Defined Under Namespace

Classes: FileLoaderError, NotFoundError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/webpacker_lite/file_loader.rb', line 7

def data
  @data
end

#mtimeObject

Returns the value of attribute mtime.



7
8
9
# File 'lib/webpacker_lite/file_loader.rb', line 7

def mtime
  @mtime
end

Class Method Details

.file_pathObject

Raises:



19
20
21
# File 'lib/webpacker_lite/file_loader.rb', line 19

def file_path
  raise FileLoaderError.new("Subclass of WebpackerLite::FileLoader should override this method")
end

.load_instance(path = file_path) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/webpacker_lite/file_loader.rb', line 10

def load_instance(path = file_path)
  # Assume production is 100% cached
  return if 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

  self.instance = new(path)
end