Class: Propshaft::LoadPath
- Inherits:
-
Object
- Object
- Propshaft::LoadPath
- Defined in:
- lib/propshaft/load_path.rb
Defined Under Namespace
Classes: NullFileWatcher
Instance Attribute Summary collapse
-
#compilers ⇒ Object
readonly
Returns the value of attribute compilers.
-
#integrity_hash_algorithm ⇒ Object
readonly
Returns the value of attribute integrity_hash_algorithm.
-
#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, file_watcher: nil, integrity_hash_algorithm: nil) ⇒ LoadPath
constructor
A new instance of LoadPath.
- #manifest ⇒ Object
Constructor Details
#initialize(paths = [], compilers:, version: nil, file_watcher: nil, integrity_hash_algorithm: nil) ⇒ LoadPath
Returns a new instance of LoadPath.
17 18 19 20 |
# File 'lib/propshaft/load_path.rb', line 17 def initialize(paths = [], compilers:, version: nil, file_watcher: nil, integrity_hash_algorithm: nil) @paths, @compilers, @version, @integrity_hash_algorithm = dedup(paths), compilers, version, integrity_hash_algorithm @file_watcher = file_watcher || NullFileWatcher end |
Instance Attribute Details
#compilers ⇒ Object (readonly)
Returns the value of attribute compilers.
15 16 17 |
# File 'lib/propshaft/load_path.rb', line 15 def compilers @compilers end |
#integrity_hash_algorithm ⇒ Object (readonly)
Returns the value of attribute integrity_hash_algorithm.
15 16 17 |
# File 'lib/propshaft/load_path.rb', line 15 def integrity_hash_algorithm @integrity_hash_algorithm end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
15 16 17 |
# File 'lib/propshaft/load_path.rb', line 15 def paths @paths end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
15 16 17 |
# File 'lib/propshaft/load_path.rb', line 15 def version @version end |
Instance Method Details
#asset_paths_by_glob(glob) ⇒ Object
39 40 41 42 |
# File 'lib/propshaft/load_path.rb', line 39 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
34 35 36 37 |
# File 'lib/propshaft/load_path.rb', line 34 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
30 31 32 |
# File 'lib/propshaft/load_path.rb', line 30 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/propshaft/load_path.rb', line 53 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 @file_watcher.new([], files_to_watch) do mutex.synchronize do clear_cache seed_cache end end end end |
#find(asset_name) ⇒ Object
22 23 24 |
# File 'lib/propshaft/load_path.rb', line 22 def find(asset_name) assets_by_path[asset_name] end |
#find_referenced_by(asset) ⇒ Object
26 27 28 |
# File 'lib/propshaft/load_path.rb', line 26 def find_referenced_by(asset) compilers.referenced_by(asset).delete(self) end |