@@ -2,14 +2,41 @@ module Propshaft
2
2
class Manifest
3
3
class ManifestEntry
4
4
attr_reader :logical_path , :digested_path , :integrity
5
+
5
6
def initialize ( logical_path :, digested_path :, integrity :)
6
7
@logical_path = logical_path
7
8
@digested_path = digested_path
8
9
@integrity = integrity
9
10
end
10
11
11
12
def to_h
12
- { digested_path :, integrity : }
13
+ { digested_path : digested_path , integrity : integrity }
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def from_path ( manifest_path )
19
+ manifest = Manifest . new
20
+
21
+ serialized_manifest = JSON . parse ( manifest_path . read , symbolize_names : false )
22
+
23
+ serialized_manifest . each_pair do |key , value |
24
+ # Compatibility mode to be able to
25
+ # read the old "simple manifest" format
26
+ digested_path , integrity = if value . is_a? ( String )
27
+ [ value , nil ]
28
+ else
29
+ [ value [ "digested_path" ] , value [ "integrity" ] ]
30
+ end
31
+
32
+ entry = ManifestEntry . new (
33
+ logical_path : key , digested_path : digested_path , integrity : integrity
34
+ )
35
+
36
+ manifest . push ( entry )
37
+ end
38
+
39
+ manifest
13
40
end
14
41
end
15
42
@@ -22,7 +49,7 @@ def push_asset(asset)
22
49
entry = ManifestEntry . new (
23
50
logical_path : asset . logical_path . to_s ,
24
51
digested_path : asset . digested_path . to_s ,
25
- integrity : @ integrity_hash_algorithm && asset . integrity ( hash_algorithm : @ integrity_hash_algorithm)
52
+ integrity : integrity_hash_algorithm && asset . integrity ( hash_algorithm : integrity_hash_algorithm )
26
53
)
27
54
28
55
push ( entry )
@@ -31,45 +58,19 @@ def push_asset(asset)
31
58
def push ( entry )
32
59
@entries [ entry . logical_path ] = entry
33
60
end
34
-
35
- def <<( asset )
36
- push ( asset )
37
- end
61
+ alias_method :<< , :push
38
62
39
63
def []( logical_path )
40
64
@entries [ logical_path ]
41
65
end
42
66
43
67
def to_json
44
- Hash . new . tap do |serialized_manifest |
45
- @entries . values . each do |manifest_entry |
46
- serialized_manifest [ manifest_entry . logical_path ] = manifest_entry . to_h
47
- end
68
+ @entries . transform_values do |manifest_entry |
69
+ manifest_entry . to_h
48
70
end . to_json
49
71
end
50
72
51
- class << self
52
- def from_path ( manifest_path )
53
- Manifest . new . tap do |manifest |
54
- JSON . parse ( manifest_path . read , symbolize_names : false ) . tap do |serialized_manifest |
55
- serialized_manifest . each_pair do |key , value |
56
- # Compatibility mode to be able to
57
- # read the old "simple manifest" format
58
- digested_path , integrity = if value . is_a? ( String )
59
- [ value , nil ]
60
- else
61
- [ value [ "digested_path" ] , value [ "integrity" ] ]
62
- end
63
-
64
- entry = ManifestEntry . new (
65
- logical_path : key , digested_path :, integrity :
66
- )
67
-
68
- manifest . push ( entry )
69
- end
70
- end
71
- end
72
- end
73
- end
73
+ private
74
+ attr_reader :integrity_hash_algorithm
74
75
end
75
76
end
0 commit comments