Class: Ucode::Fetch::SpecialistFontFetcher
- Inherits:
-
Object
- Object
- Ucode::Fetch::SpecialistFontFetcher
- Defined in:
- lib/ucode/fetch/specialist_font_fetcher.rb
Overview
Concrete font fetcher: walks a Models::SpecialistFontManifest
and materializes each font's path on disk.
Behavior (per acceptance in TODO 30):
- Idempotent. A font whose
pathalready exists with the manifest's SHA256 is:skipped. A file with a mismatched hash is re-downloaded. - Hashed. On download, SHA256 is computed. If the manifest has a hash, mismatch raises Ucode::FontChecksumError. If the manifest hash is null, the computed hash is written back to the YAML at the end of the run (atomic write).
- License-checked. Non-OFL entries require
allow_proprietary: true; otherwise the result is:failedwith Ucode::FontLicenseError. - Extracted.
extract: trueentries unzip to a temp dir and onlyextract_memberis moved into place. - Local-only.
url: nullentries are never fetched over the network; the result is:localwhether or not the file is yet present (with anoteinstructing placement when missing).
A single font failure does not abort the run. The fetcher returns an array of FontFetcher::Result; the caller decides how to report failures.
Instance Method Summary collapse
-
#call(only_label: nil) ⇒ Array<FontFetcher::Result>
One per manifest entry actually visited, in declared order.
-
#initialize(manifest_path:, fonts_root: ".", allow_proprietary: false, dry_run: false, http: Fetch::Http) ⇒ SpecialistFontFetcher
constructor
A new instance of SpecialistFontFetcher.
Constructor Details
#initialize(manifest_path:, fonts_root: ".", allow_proprietary: false, dry_run: false, http: Fetch::Http) ⇒ SpecialistFontFetcher
Returns a new instance of SpecialistFontFetcher.
54 55 56 57 58 59 60 61 62 |
# File 'lib/ucode/fetch/specialist_font_fetcher.rb', line 54 def initialize(manifest_path:, fonts_root: ".", allow_proprietary: false, dry_run: false, http: Fetch::Http) @manifest_path = Pathname.new(manifest_path) @fonts_root = Pathname.new(fonts_root) @allow_proprietary = allow_proprietary @dry_run = dry_run @http = http @computed_hashes = {} end |
Instance Method Details
#call(only_label: nil) ⇒ Array<FontFetcher::Result>
Returns one per manifest entry actually visited, in declared order.
68 69 70 71 72 73 74 75 76 |
# File 'lib/ucode/fetch/specialist_font_fetcher.rb', line 68 def call(only_label: nil) manifest = load_manifest return [unknown_label_result(only_label)] if only_label && manifest.find_by_label(only_label).nil? entries = only_label ? [manifest.find_by_label(only_label)] : manifest.fonts results = entries.map { |font| fetch_one(font) } persist_computed_hashes(manifest) unless @dry_run results end |