Class: Tebako::ContentManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/tebako/content_manifest.rb

Overview

Builds deterministic, content-addressed manifests for package inputs.

Constant Summary collapse

VERSION =
1
BUFFER_SIZE =
1024 * 1024

Class Method Summary collapse

Class Method Details

.digest_tree(root, excluded: []) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/tebako/content_manifest.rb', line 39

def digest_tree(root, excluded: [])
  root = File.expand_path(root)
  exclusions = excluded.compact.map { |path| File.expand_path(path) }
  digest = Digest::SHA256.new
  digest_directory(digest, root, "", exclusions)
  digest.hexdigest
end

.serialize(root:, metadata:, excluded: []) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/tebako/content_manifest.rb', line 55

def serialize(root:, metadata:, excluded: [])
  JSON.generate(
    "version" => VERSION,
    "root" => File.expand_path(root),
    "tree" => digest_tree(root, excluded: excluded),
    "metadata" => .transform_keys(&:to_s).sort.to_h
  )
end

.stat_digest_tree(root, excluded: []) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/tebako/content_manifest.rb', line 47

def stat_digest_tree(root, excluded: [])
  root = File.expand_path(root)
  exclusions = excluded.compact.map { |path| File.expand_path(path) }
  digest = Digest::SHA256.new
  digest_stat_directory(digest, root, "", exclusions)
  digest.hexdigest
end