Class: ArchSpec::RubydexIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rubydex_index.rb

Overview

Translates Rubydex's semantic index into the small graph ArchSpec's rules consume. Rubydex owns Ruby semantics here: declarations, constant resolution, ancestry and methods all come from its resolved graph. The Prism pass in Analyzer adds only syntax facts Rubydex does not expose.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths, syntax:, method_names: []) ⇒ RubydexIndex

Returns a new instance of RubydexIndex.



17
18
19
20
21
22
# File 'lib/archspec/rubydex_index.rb', line 17

def initialize(paths, syntax:, method_names: [])
  @paths = paths.map { |path| File.expand_path(path) }.to_set
  @syntax = syntax
  @configured_method_names = method_names.to_set
  @call_resolutions = {}
end

Instance Attribute Details

#call_resolutionsObject (readonly)

Returns the value of attribute call_resolutions.



15
16
17
# File 'lib/archspec/rubydex_index.rb', line 15

def call_resolutions
  @call_resolutions
end

Instance Method Details

#populate(graph) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archspec/rubydex_index.rb', line 24

def populate(graph)
  @index = ::Rubydex::Graph.new
  @index.encoding = 'utf8'
  @index.index_all(paths.to_a.sort)
  @index.resolve

  add_constants(graph)
  add_methods(graph)
  add_ancestry(graph)
  add_constant_references(graph)
  resolve_call_sites
  add_diagnostics(graph)
  graph
rescue ::Rubydex::Error, IOError, SystemCallError => error
  raise Error, "Rubydex could not index the project: #{error.message.lines.first&.strip}"
end