Class: LocoMotion::Icons::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/loco_motion/icons/verifier.rb

Overview

Checks that every icon reference resolves from the given icon roots — typically the application's vendored app/assets/svg/icons plus the engine's bundled set, deliberately excluding the development-only local cache the Renderer may fall back to. That makes it the treeshake's audit step: loco_motion:icons:verify uses it to fail loudly when a referenced icon has not been vendored, no matter which environment the app happens to be running in.

Like Vendorer, it is pure file I/O and mirrors the renderer's path resolution — <library>/<variant>/<name>.svg, with a nil variant (flat library) collapsing to <library>/<name>.svg.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(roots:, default_variant:) ⇒ Verifier

Returns a new instance of Verifier.

Parameters:

  • roots (Array<String>)

    Icon root directories to resolve against, in the renderer's precedence order (the application's vendored set, then the engine's bundled set).

  • default_variant (String, Symbol, nil)

    Variant used for references that do not specify one (mirrors the renderer's default).



31
32
33
34
# File 'lib/loco_motion/icons/verifier.rb', line 31

def initialize(roots:, default_variant:)
  @roots = Array(roots).map(&:to_s)
  @default_variant = default_variant
end

Instance Method Details

#verify(references) ⇒ Result

Returns The count of references that resolved and the references that resolved from none of the roots.

Parameters:

  • references (Array<Hash>)

    { library:, variant:, name: } entries, as produced by Scanner / Reference.

Returns:

  • (Result)

    The count of references that resolved and the references that resolved from none of the roots.



44
45
46
47
48
# File 'lib/loco_motion/icons/verifier.rb', line 44

def verify(references)
  missing = references.reject { |ref| resolves?(ref) }

  Result.new(verified: references.size - missing.size, missing: missing)
end