Class: MetzScan::ProjectIndex::RubydexBackend
- Inherits:
-
Object
- Object
- MetzScan::ProjectIndex::RubydexBackend
show all
- Extended by:
- FileDiscovery
- Includes:
- LocationFormatting, MethodDeclarations
- Defined in:
- lib/metz_scan/project_index/rubydex_backend.rb,
lib/metz_scan/project_index/rubydex_backend/file_discovery.rb,
lib/metz_scan/project_index/rubydex_backend/location_formatting.rb,
lib/metz_scan/project_index/rubydex_backend/method_declarations.rb
Defined Under Namespace
Modules: FileDiscovery, LocationFormatting, MethodDeclarations
Constant Summary
collapse
- DECLARATION_KINDS =
{ "Rubydex::Class" => :class, "Rubydex::Module" => :module }.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
ruby_files_for, workspace_path_for
#method_declarations
#path_from_file_location, #path_from_location, #path_from_uri, #path_from_uri_location
Constructor Details
#initialize(graph:, indexed_files:, index_errors:) ⇒ RubydexBackend
Returns a new instance of RubydexBackend.
44
45
46
47
48
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 44
def initialize(graph:, indexed_files:, index_errors:)
@graph = graph
@indexed_files = indexed_files
@index_errors = Array(index_errors)
end
|
Instance Attribute Details
#graph ⇒ Object
Returns the value of attribute graph.
50
51
52
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 50
def graph
@graph
end
|
#index_errors ⇒ Object
Returns the value of attribute index_errors.
50
51
52
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 50
def index_errors
@index_errors
end
|
#indexed_files ⇒ Object
Returns the value of attribute indexed_files.
50
51
52
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 50
def indexed_files
@indexed_files
end
|
Class Method Details
.available? ⇒ Boolean
16
17
18
19
20
21
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 16
def self.available?
require "rubydex"
true
rescue LoadError
false
end
|
.build(paths, workspace: false) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 27
def self.build(paths, workspace: false)
require "rubydex"
files = ruby_files_for(paths)
graph = Rubydex::Graph.new(workspace_path: workspace_path_for(paths))
index_errors = index_graph(graph, files, workspace)
new(graph: graph, indexed_files: files, index_errors: index_errors)
end
|
.unavailable_reason ⇒ Object
23
24
25
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 23
def self.unavailable_reason
"rubydex is not installed; enable the optional rubydex bundle group first"
end
|
Instance Method Details
#available? ⇒ Boolean
54
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 54
def available? = true
|
#constant_references_to(name) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 82
def constant_references_to(name)
declaration = graph[name]
return [] unless declaration.respond_to?(:references)
declaration.references.map { |reference| normalized_reference(reference) }.compact.sort_by do |reference|
[reference.path.to_s, reference.line.to_i, reference.column.to_i, reference.name.to_s]
end
end
|
#declarations ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 62
def declarations
entries = graph.declarations.map do |declaration|
Declaration.new(name: declaration.name, path: definition_path(declaration),
kind: declaration_kind(declaration))
end
entries.sort_by { |declaration| [declaration.name.to_s, declaration.path.to_s] }
end
|
#descendants_of(name) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 75
def descendants_of(name)
declaration = graph[name]
return [] unless declaration.respond_to?(:descendants)
declaration.descendants.map(&:name).reject { |descendant| descendant == name }.sort
end
|
#diagnostics ⇒ Object
58
59
60
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 58
def diagnostics
graph.diagnostics.to_a
end
|
#documents ⇒ Object
71
72
73
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 71
def documents
graph.documents.map { |document| path_from_uri(document.uri) }.compact.sort
end
|
#name ⇒ Object
52
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 52
def name = :rubydex
|
#reason ⇒ Object
56
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 56
def reason = nil
|
#search(query) ⇒ Object
91
92
93
|
# File 'lib/metz_scan/project_index/rubydex_backend.rb', line 91
def search(query)
graph.search(query).map(&:name).sort
end
|