Class: Propshaft::LoadPath
- Inherits:
-
Object
- Object
- Propshaft::LoadPath
- Defined in:
- lib/propshaft/load_path.rb
Instance Attribute Summary collapse
-
#compilers ⇒ Object
readonly
Returns the value of attribute compilers.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #asset_paths_by_glob(glob) ⇒ Object
- #asset_paths_by_type(content_type) ⇒ Object
- #assets ⇒ Object
-
#cache_sweeper ⇒ Object
Returns a file watcher object configured to clear the cache of the load_path when the directories passed during its initialization have changes.
- #find(asset_name) ⇒ Object
- #find_referenced_by(asset) ⇒ Object
-
#initialize(paths = [], compilers:, version: nil) ⇒ LoadPath
constructor
A new instance of LoadPath.
- #manifest ⇒ Object
Constructor Details
#initialize(paths = [], compilers:, version: nil) ⇒ LoadPath
Returns a new instance of LoadPath.
6 7 8 |
# File 'lib/propshaft/load_path.rb', line 6 def initialize(paths = [], compilers:, version: nil) @paths, @compilers, @version = dedup(paths), compilers, version end |
Instance Attribute Details
#compilers ⇒ Object (readonly)
Returns the value of attribute compilers.
4 5 6 |
# File 'lib/propshaft/load_path.rb', line 4 def compilers @compilers end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
4 5 6 |
# File 'lib/propshaft/load_path.rb', line 4 def paths @paths end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/propshaft/load_path.rb', line 4 def version @version end |
Instance Method Details
#asset_paths_by_glob(glob) ⇒ Object
27 28 29 30 |
# File 'lib/propshaft/load_path.rb', line 27 def asset_paths_by_glob(glob) (@cached_asset_paths_by_glob ||= Hash.new)[glob] ||= extract_logical_paths_from(assets.select { |a| a.path.fnmatch?(glob) }) end |
#asset_paths_by_type(content_type) ⇒ Object
22 23 24 25 |
# File 'lib/propshaft/load_path.rb', line 22 def asset_paths_by_type(content_type) (@cached_asset_paths_by_type ||= Hash.new)[content_type] ||= extract_logical_paths_from(assets.select { |a| a.content_type == Mime::EXTENSION_LOOKUP[content_type] }) end |
#assets ⇒ Object
18 19 20 |
# File 'lib/propshaft/load_path.rb', line 18 def assets assets_by_path.values end |
#cache_sweeper ⇒ Object
Returns a file watcher object configured to clear the cache of the load_path when the directories passed during its initialization have changes. This is used in development and test to ensure the map caches are reset when javascript files are changed.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/propshaft/load_path.rb', line 43 def cache_sweeper @cache_sweeper ||= begin exts_to_watch = Mime::EXTENSION_LOOKUP.map(&:first) files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h mutex = Mutex.new Rails.application.config.file_watcher.new([], files_to_watch) do mutex.synchronize do clear_cache seed_cache end end end end |
#find(asset_name) ⇒ Object
10 11 12 |
# File 'lib/propshaft/load_path.rb', line 10 def find(asset_name) assets_by_path[asset_name] end |
#find_referenced_by(asset) ⇒ Object
14 15 16 |
# File 'lib/propshaft/load_path.rb', line 14 def find_referenced_by(asset) compilers.referenced_by(asset).delete(self) end |
#manifest ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/propshaft/load_path.rb', line 32 def manifest Hash.new.tap do |manifest| assets.each do |asset| manifest[asset.logical_path.to_s] = asset.digested_path.to_s end end end |