Class: Fontico::Resolver
- Inherits:
-
Object
- Object
- Fontico::Resolver
- Defined in:
- lib/fontico/resolver.rb
Overview
Turns manifest entries into raw SVG. Vendor icons come from the Iconify API in one batched request per provider; first-party icons come off disk.
Defined Under Namespace
Constant Summary collapse
- API =
"https://api.iconify.design"- MAX_ALIAS_DEPTH =
Guards a malformed set; real chains are one or two hops.
8
Instance Attribute Summary collapse
-
#missing ⇒ Object
readonly
{ "save" => "lucide/save: not found in provider lucide" } — icons this run could not resolve.
Instance Method Summary collapse
-
#call(only: nil) ⇒ Object
=> { "save" => Source, ... } keyed by icon name.
-
#initialize(manifest, root: Dir.pwd, api: API) ⇒ Resolver
constructor
A new instance of Resolver.
Constructor Details
Instance Attribute Details
#missing ⇒ Object (readonly)
{ "save" => "lucide/save: not found in provider lucide" } — icons this run could not resolve. Filled by #call; see the comment there.
22 23 24 |
# File 'lib/fontico/resolver.rb', line 22 def missing @missing end |
Instance Method Details
#call(only: nil) ⇒ Object
=> { "save" => Source, ... } keyed by icon name.
One bad name in a manifest of two hundred used to take the whole build down, which meant a typo in an icon nobody had shipped yet blocked everyone. A single icon failing is now recorded in #missing and left out of the result; the caller reports it and builds the rest. Failures that are not per-icon — an unreachable API, a provider that 404s — are still raised, because then nothing would be correct.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fontico/resolver.rb', line 39 def call(only: nil) icons = @manifest.icons icons = icons.select { only.include?(_1.name) } if only resolved = {} icons.select(&:local?).each do |icon| try(icon) { resolved[icon.name] = local(icon) } end icons.reject(&:local?).group_by(&:provider).each do |provider, group| payload = fetch(provider, group.map(&:slug).uniq.sort) group.each { |icon| try(icon) { resolved[icon.name] = remote(icon, payload) } } end resolved end |