File: static.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 (38 lines) | stat: -rw-r--r-- 862 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
35
36
37
38
module Propshaft::Resolver
  class Static
    attr_reader :manifest_path, :prefix

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

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

    def integrity(logical_path)
      entry = manifest[logical_path]

      entry&.integrity
    end

    def read(logical_path, encoding: "ASCII-8BIT")
      if asset_path = digested_path(logical_path)
        File.read(manifest_path.dirname.join(asset_path), encoding: encoding)
      end
    end

    private
      def manifest
        @manifest ||= Propshaft::Manifest.from_path(manifest_path)
      end

      def digested_path(logical_path)
        entry = manifest[logical_path]

        entry&.digested_path
      end
  end
end