Class: BunBunBundle::Manifest

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

Defined Under Namespace

Classes: MissingAssetError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries = {}) ⇒ Manifest

Returns a new instance of Manifest.



11
12
13
# File 'lib/bun_bun_bundle/manifest.rb', line 11

def initialize(entries = {})
  @entries = entries.freeze
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



9
10
11
# File 'lib/bun_bun_bundle/manifest.rb', line 9

def entries
  @entries
end

Class Method Details

.load(path: nil, root: Dir.pwd, retries: 10, delay: 0.25) ⇒ Object

Loads the manifest from a JSON file.

Retries a configurable number of times to allow for the manifest to be built during boot (e.g. in development).



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bun_bun_bundle/manifest.rb', line 19

def self.load(path: nil, root: Dir.pwd, retries: 10, delay: 0.25)
  path ||= BunBunBundle.config.manifest_path
  full_path = File.expand_path(path, root)

  retries.times do
    if File.exist?(full_path)
      data = JSON.parse(File.read(full_path))
      return new(data)
    end
    sleep(delay)
  end

  raise "Manifest not found at #{full_path}. Run: bun_bun_bundle build"
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/bun_bun_bundle/manifest.rb', line 34

def [](key)
  entries.fetch(key) do
    suggestion = find_similar(key)
    message = "Asset not found: #{key}"
    message += ". Did you mean: #{suggestion}?" if suggestion
    raise MissingAssetError, message
  end
end

#css_entry_pointsObject



47
48
49
# File 'lib/bun_bun_bundle/manifest.rb', line 47

def css_entry_points
  entries.keys.select { |k| k.end_with?('.css') }
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

def key?(key)
  entries.key?(key)
end