Class: Glyphs::SourceScanner::DynamicHarvest
- Inherits:
-
Object
- Object
- Glyphs::SourceScanner::DynamicHarvest
- Defined in:
- lib/glyphs/source_scanner.rb
Overview
Accumulates the evidence needed to resolve DYNAMIC icon calls — ones whose
name the AST can't read (LucideIcon(tile[:icon])) — across every scanned
Ruby file, then turns that evidence into IconReferences.
Two sources of candidate names, both harvested only from literals so we never invent a reference:
1. file-scoped — a file that dynamically renders library L contributes
every icon-name-shaped literal in that file as a candidate for L.
Catches ternaries, case/when, and locals near the call.
2. declaration-based — literals in icon-declaration positions ANYWHERE
(a hash pair keyed `/icon/i`, or a constant named `/ICON/`) are
candidates for EVERY dynamically-rendered library, since a bare
`ICON = :bell` in one file is often rendered from another.
Names resolve at the library's default variant: a dynamic call names no variant in practice, and the pruner keeps per (library, variant).
Instance Method Summary collapse
-
#absorb(visitor) ⇒ Object
Folds one file's visitor results into the running accumulator.
-
#initialize ⇒ DynamicHarvest
constructor
A new instance of DynamicHarvest.
-
#to_h ⇒ Object
{ library => Set[candidate names] }for every dynamically-rendered library.
Constructor Details
#initialize ⇒ DynamicHarvest
Returns a new instance of DynamicHarvest.
173 174 175 176 177 |
# File 'lib/glyphs/source_scanner.rb', line 173 def initialize @dynamic_libraries = Set.new @file_literals = Hash.new { |hash, key| hash[key] = Set.new } @declaration_literals = Set.new end |
Instance Method Details
#absorb(visitor) ⇒ Object
Folds one file's visitor results into the running accumulator.
180 181 182 183 184 185 186 187 188 |
# File 'lib/glyphs/source_scanner.rb', line 180 def absorb(visitor) @declaration_literals.merge(visitor.declaration_literals) return if visitor.dynamic_libraries.empty? @dynamic_libraries.merge(visitor.dynamic_libraries) visitor.dynamic_libraries.each do |library| @file_literals[library].merge(visitor.file_literals) end end |
#to_h ⇒ Object
{ library => Set[candidate names] } for every dynamically-rendered
library. Advisory: names may not be real icons, so callers keep them but
must not assert they exist.
193 194 195 196 197 |
# File 'lib/glyphs/source_scanner.rb', line 193 def to_h @dynamic_libraries.to_h do |library| [library, @file_literals[library] | @declaration_literals] end end |