Class: ArchUnit::Extraction::ImportResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/archunit/extraction/import_resolver.rb

Overview

Resolves one source file’s imports and reuses context-independent feature lookups.

Instance Method Summary collapse

Constructor Details

#initialize(source_path:, project_root:, load_paths:, profile: nil, cache: nil) ⇒ ImportResolver

Returns a new instance of ImportResolver.



11
12
13
14
15
16
17
# File 'lib/archunit/extraction/import_resolver.rb', line 11

def initialize(source_path:, project_root:, load_paths:, profile: nil, cache: nil)
  @source_path = source_path
  @project_root = project_root
  @load_paths = load_paths
  @profile = profile
  @cache = cache
end

Instance Method Details

#resolve(module_name, import_kind) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/archunit/extraction/import_resolver.rb', line 19

def resolve(module_name, import_kind)
  key = cache_key(module_name, import_kind)
  return cached_resolution(key) if @cache&.key?(key)

  @profile&.increment(:resolution_cache_misses) if @cache
  resolution = uncached_resolution(module_name, import_kind)
  @cache[key] = resolution if @cache
  resolution
end