Class: RubyLens::Index::RubydexAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/index/rubydex_adapter.rb

Overview

Drives one Rubydex indexing run over the manifest and assembles the snapshot payload from what the collectors return.

The snapshot is the privacy boundary: every namespace and dependency star leaves here as a row of integers, and the only strings that survive are namespace names, package names, and the project name.

Constant Summary collapse

SCHEMA =
"rubylens.snapshot.v9"
RSPEC_ROW =
[0, 1, *Array.new(11, 0)].freeze

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ RubydexAdapter

The manifest is duck-typed: production passes a Manifest, tests pass stubs, and index probes it with respond_to? for the optional parts.

: (untyped manifest) -> void



26
27
28
29
# File 'lib/rubylens/index/rubydex_adapter.rb', line 26

def initialize(manifest)
  @manifest = manifest
  @locations = LocationIndex.new(manifest)
end

Instance Method Details

#indexObject

: () -> Hash[String, untyped]



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rubylens/index/rubydex_adapter.rb', line 32

def index
  graph = Rubydex::Graph.new(workspace_path: @manifest.root.to_s)
  index_errors = graph.index_all(@manifest.files)
  # Documents resolve before `resolve` so package attribution sees exactly
  # the documents Rubydex accepted, not the paths the manifest offered.
  documents_with_paths = @locations.resolve_documents(graph)
  graph.resolve
  integrity_failures = graph.check_integrity

  collected = DeclarationCollector.new(manifest: @manifest, locations: @locations).call(graph.declarations)
  rspec = RSpecExtractor.new(
    graph: graph,
    manifest: @manifest,
    package_document_paths: @locations.package_document_paths,
    documents_with_paths: documents_with_paths,
  ).call

  namespaces = collected.namespaces
  namespace_names = namespaces.map(&:name) + rspec.groups
  references = ConstantReferenceCollector.new(locations: @locations).call(
    graph: graph,
    namespaces: namespaces,
    definition_ranges: collected.definition_ranges,
    ordinal_by_name: ordinal_by_name(namespaces),
    dependency_ordinal_by_name: collected.dependency_ordinal_by_name,
    namespace_count: namespace_names.length,
  )

  category_stats = collected.category_stats
  category_stats.fetch("tests")[0] += rspec.groups.length
  category_stats.fetch("tests")[2] += rspec.method_count

  {
    "schema" => SCHEMA,
    "project_name" => project_name,
    "namespace_names" => namespace_names,
    "namespaces" => namespace_rows(namespaces, references.inbound_counts, rspec.groups.length),
    "constant_reference_links" => references.links,
    "category_stats" => category_stats,
    "dependency_signal_maxima" => collected.dependency_signal_maxima,
    "packages" => package_rows(collected.dependency_packages),
    "dependency_systems" => dependency_system_rows,
    "dependency_warnings" => @manifest.respond_to?(:dependency_warnings) ? @manifest.dependency_warnings : [],
    "warning_counts" => {
      "manifest" => @manifest.warnings.length,
      "index" => index_errors.length,
      "integrity" => integrity_failures.length,
    },
  }
end