Class: Propshaft::LoadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/propshaft/load_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = []) ⇒ LoadPath

Returns a new instance of LoadPath.



6
7
8
# File 'lib/propshaft/load_path.rb', line 6

def initialize(paths = [])
  @paths = Array(paths).collect { |path| Pathname.new(path) }
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



4
5
6
# File 'lib/propshaft/load_path.rb', line 4

def paths
  @paths
end

Instance Method Details

#assets(content_types: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/propshaft/load_path.rb', line 14

def assets(content_types: nil)
  if content_types
    assets_by_path.values.select { |asset| asset.content_type.in?(content_types) }
  else
    assets_by_path.values
  end
end

#cache_sweeperObject

Returns a ActiveSupport::FileUpdateChecker 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.



33
34
35
36
37
38
39
40
41
42
# File 'lib/propshaft/load_path.rb', line 33

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

    Rails.application.config.file_watcher.new([], files_to_watch) do
      clear_cache
    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

#manifestObject



22
23
24
25
26
27
28
# File 'lib/propshaft/load_path.rb', line 22

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