Class: Minipack::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/minipack/manifest.rb

Defined Under Namespace

Classes: ChunkGroup, Entry, FileNotFoundError, MissingEntryError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, cache: false) ⇒ Manifest

Returns a new instance of Manifest.



45
46
47
48
# File 'lib/minipack/manifest.rb', line 45

def initialize(path, cache: false)
  @path = path.to_s
  @cache = cache
end

Instance Attribute Details

#cache=(value) ⇒ Object (writeonly)

Sets the attribute cache

Parameters:

  • value

    the value to set the attribute cache to.



43
44
45
# File 'lib/minipack/manifest.rb', line 43

def cache=(value)
  @cache = value
end

#pathObject (readonly)

Returns the value of attribute path.



42
43
44
# File 'lib/minipack/manifest.rb', line 42

def path
  @path
end

Instance Method Details

#assetsObject



79
80
81
# File 'lib/minipack/manifest.rb', line 79

def assets
  data.values
end

#cache_enabled?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/minipack/manifest.rb', line 83

def cache_enabled?
  @cache
end

#find(name) ⇒ Minipack::Entry

Find an entry by it’s name

Parameters:

  • name (Symbol)

    entry name

Returns:

  • (Minipack::Entry)


70
71
72
73
74
75
76
77
# File 'lib/minipack/manifest.rb', line 70

def find(name)
  path = data[name.to_s] || return
  if path.is_a? Hash
    integrity = path['integrity']
    path = path['src']
  end
  Entry.new(path, integrity: integrity)
end

#lookup!(name) ⇒ Object



62
63
64
# File 'lib/minipack/manifest.rb', line 62

def lookup!(name)
  find(name) || handle_missing_entry(name)
end

#lookup_pack_with_chunks!(name, type: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/minipack/manifest.rb', line 50

def lookup_pack_with_chunks!(name, type: nil)
  manifest_pack_type = manifest_type(name, type)
  manifest_pack_name = manifest_name(name, manifest_pack_type)
  paths = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type) || handle_missing_entry(name)

  entries = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type).map do |source|
    entry_from_source(source) || handle_missing_entry(name)
  end

  ChunkGroup.new(entries)
end