Class: Lumin::CacheManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/lumin/cache_manifest.rb

Defined Under Namespace

Classes: Contents, PathEntry

Constant Summary collapse

VERSION =
2
DIGEST_PATTERN =
/\A[0-9a-f]{64}\z/
LOCATION_KEYS =
%w[start_offset end_offset start_line start_column end_line end_column].freeze

Class Method Summary collapse

Class Method Details

.emptyObject



39
40
41
# File 'lib/lumin/cache_manifest.rb', line 39

def empty
  Contents.new(paths: {}, offenses: {})
end

.load(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lumin/cache_manifest.rb', line 16

def load(path)
  return empty unless File.file?(path)

  payload = File.open(path, "rb") do |file|
    JSON.parse(file.read, create_additions: false, max_nesting: 20)
  end
  return empty unless payload.is_a?(Hash) && payload["version"] == VERSION

  decode(payload)
rescue StandardError
  empty
end

.serialize(data) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/lumin/cache_manifest.rb', line 29

def serialize(data)
  JSON.generate(
    "version" => VERSION,
    "paths" => data.paths.map { |path, entry| encode_path_entry(path, entry) },
    "offenses" => data.offenses.transform_values do |entries|
      entries.map { |entry| encode_offense(entry) }
    end
  )
end