Class: BunBunBundle::Manifest
- Inherits:
-
Object
- Object
- BunBunBundle::Manifest
- Defined in:
- lib/bun_bun_bundle/manifest.rb
Defined Under Namespace
Classes: MissingAssetError
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Class Method Summary collapse
-
.load(path: nil, root: Dir.pwd, retries: 10, delay: 0.25) ⇒ Object
Loads the manifest from a JSON file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #css_entry_points ⇒ Object
-
#initialize(entries = {}) ⇒ Manifest
constructor
A new instance of Manifest.
- #key?(key) ⇒ Boolean
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
#entries ⇒ Object (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.(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) = "Asset not found: #{key}" += ". Did you mean: #{suggestion}?" if suggestion raise MissingAssetError, end end |
#css_entry_points ⇒ Object
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
43 44 45 |
# File 'lib/bun_bun_bundle/manifest.rb', line 43 def key?(key) entries.key?(key) end |