Class: BunBunBundle::Manifest

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

Defined Under Namespace

Classes: Entry, InvalidEntryError, MigrationError, MissingAssetError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries = {}) ⇒ Manifest

Returns a new instance of Manifest.



28
29
30
31
32
# File 'lib/bun_bun_bundle/manifest.rb', line 28

def initialize(entries = {})
  @entries = entries.transform_values do |value|
    value.is_a?(Entry) ? value : Entry.from(value)
  end.freeze
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



26
27
28
# File 'lib/bun_bun_bundle/manifest.rb', line 26

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).



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bun_bun_bundle/manifest.rb', line 38

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



53
54
55
56
57
58
59
60
# File 'lib/bun_bun_bundle/manifest.rb', line 53

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



66
67
68
# File 'lib/bun_bun_bundle/manifest.rb', line 66

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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