Class: Propshaft::OutputPath

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, manifest) ⇒ OutputPath

Returns a new instance of OutputPath.



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

def initialize(path, manifest)
  @path, @manifest = path, manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



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

def manifest
  @manifest
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#clean(count, age) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/propshaft/output_path.rb', line 10

def clean(count, age)
  asset_versions = files.group_by { |_, attrs| attrs[:logical_path] }
  asset_versions.each do |logical_path, versions|
    current = manifest[logical_path]

    versions
      .reject { |path, _| current && path == current }
      .sort_by { |_, attrs| attrs[:mtime] }
      .reverse
      .each_with_index
      .drop_while { |(_, attrs), index| fresh_version_within_limit(attrs[:mtime], count, expires_at: age, limit: index) }
      .each { |(path, _), _| remove(path) }
  end
end

#filesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/propshaft/output_path.rb', line 25

def files
  Hash.new.tap do |files|
    all_files_from_tree(path).each do |file|
      digested_path = file.relative_path_from(path)
      logical_path, digest = extract_path_and_digest(digested_path)

      files[digested_path.to_s] = {
        logical_path: logical_path.to_s,
        digest: digest,
        mtime: File.mtime(file)
      }
    end
  end
end