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 = [], version: nil) ⇒ LoadPath

Returns a new instance of LoadPath.



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

def initialize(paths = [], version: nil)
  @paths   = dedup(paths)
  @version = version
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

#versionObject (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

#assets(content_types: nil) ⇒ Object



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

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.



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

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



11
12
13
# File 'lib/propshaft/load_path.rb', line 11

def find(asset_name)
  assets_by_path[asset_name]
end

#manifestObject



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

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