lib/propshaft/load_path.rb in propshaft-0.5.0 vs lib/propshaft/load_path.rb in propshaft-0.6.0

- old
+ new

@@ -1,12 +1,13 @@ require "propshaft/asset" class Propshaft::LoadPath - attr_reader :paths + attr_reader :paths, :version - def initialize(paths = []) - @paths = Array(paths).collect { |path| Pathname.new(path) } + def initialize(paths = [], version: nil) + @paths = Array(paths).collect { |path| Pathname.new(path) } + @version = version end def find(asset_name) assets_by_path[asset_name] end @@ -43,19 +44,23 @@ private def assets_by_path @cached_assets_by_path ||= Hash.new.tap do |mapped| paths.each do |path| - all_files_from_tree(path).each do |file| + without_dotfiles(all_files_from_tree(path)).each do |file| logical_path = file.relative_path_from(path) - mapped[logical_path.to_s] ||= Propshaft::Asset.new(file, logical_path: logical_path) + mapped[logical_path.to_s] ||= Propshaft::Asset.new(file, logical_path: logical_path, version: version) end if path.exist? end end end def all_files_from_tree(path) path.children.flat_map { |child| child.directory? ? all_files_from_tree(child) : child } + end + + def without_dotfiles(files) + files.reject { |file| file.basename.to_s.starts_with?(".") } end def clear_cache @cached_assets_by_path = nil end