class WebpackerLite::FileLoader
Provides a base singleton-configuration pattern for loading a JSON or YAML file, given a path
Attributes
data[RW]
mtime[RW]
Public Class Methods
file_path()
click to toggle source
# 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)
click to toggle source
# 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
new(path)
click to toggle source
# File lib/webpacker_lite/file_loader.rb, line 32 def initialize(path) @path = path @mtime = File.exist?(path) ? File.mtime(path) : nil @data = load_data end
Private Class Methods
env()
click to toggle source
Prefer the NODE_ENV to the rails env.
# File lib/webpacker_lite/file_loader.rb, line 26 def env ENV["NODE_ENV"].presence || Rails.env end
Private Instance Methods
load_data()
click to toggle source
# File lib/webpacker_lite/file_loader.rb, line 38 def load_data {}.freeze end