lib/dassets.rb in dassets-0.14.5 vs lib/dassets.rb in dassets-0.15.0
- old
+ new
@@ -1,20 +1,26 @@
-require 'dassets/version'
-require 'dassets/asset_file'
-require 'dassets/config'
-require 'dassets/source_file'
+# frozen_string_literal: true
+require "dassets/version"
+require "dassets/asset_file"
+require "dassets/config"
+require "dassets/source_file"
+
module Dassets
+ AssetFileError = Class.new(RuntimeError)
- def self.config; @config ||= Config.new; end
+ def self.config
+ @config ||= Config.new
+ end
+
def self.configure(&block)
block.call(self.config)
end
def self.init
- @asset_files ||= {}
- @source_files = SourceFiles.new(self.config.sources)
+ @asset_files ||= {}
+ @source_files = SourceFiles.new(self.config.sources)
end
def self.reset
@asset_files = {}
self.config.reset
@@ -25,24 +31,25 @@
end
def self.[](digest_path)
self.asset_file(digest_path).tap do |af|
if af.fingerprint.nil?
- msg = "error digesting `#{digest_path}`.\n\nMake sure Dassets has " \
- "either a combination or source file for this digest path. If " \
- "this path is for a combination, make sure Dassets has either " \
- "a combination or source file for each digest path of the " \
- "combination.\n\n"
+ msg =
+ +"error digesting `#{digest_path}`.\n\nMake sure Dassets has " \
+ "either a combination or source file for this digest path. If " \
+ "this path is for a combination, make sure Dassets has either " \
+ "a combination or source file for each digest path of the " \
+ "combination.\n\n"
msg << "\nCombination digest paths:"
msg << (Dassets.combinations.keys.empty? ? " (none)\n\n" : "\n\n")
Dassets.combinations.keys.sort.each do |key|
bullet = "#{key} => "
values = Dassets.combinations[key].sort
msg << (
["#{bullet}#{values.first}"] +
- (values[1..-1] || []).map{ |v| "#{' '*bullet.size}#{v}" }
+ (values[1..-1] || []).map{ |v| "#{" "*bullet.size}#{v}" }
).join("\n")
msg << "\n\n"
end
msg << "\nSource file digest paths:"
@@ -61,11 +68,10 @@
def self.combinations
self.config.combinations
end
module SourceFiles
-
def self.new(sources)
# use a hash to store the source files so in the case two source files
# have the same digest path, the last one *should* be correct since it
# was last to be configured
sources.inject({}) do |hash, source|
@@ -74,13 +80,9 @@
hash[s.digest_path] = s
end
hash
end
end
-
end
-
- AssetFileError = Class.new(RuntimeError)
-
end
Dassets.init