File: dynamic.rb

package info (click to toggle)
ruby-propshaft 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 172 kB
  • sloc: ruby: 782; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Propshaft::Resolver
  class Dynamic
    attr_reader :load_path, :prefix

    def initialize(load_path:, prefix:)
      @load_path, @prefix = load_path, prefix
    end

    def resolve(logical_path)
      if asset = find_asset(logical_path)
        File.join prefix, asset.digested_path
      end
    end

    def integrity(logical_path)
      hash_algorithm = load_path.integrity_hash_algorithm

      if hash_algorithm && (asset = find_asset(logical_path))
        asset.integrity(hash_algorithm: hash_algorithm)
      end
    end

    def read(logical_path, options = {})
      if asset = load_path.find(logical_path)
        asset.content(**options)
      end
    end

    private
      def find_asset(logical_path)
        load_path.find(logical_path)
      end
  end
end