Class: RailsAiBridge::RubydexAdapter::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/rubydex_adapter/indexer.rb

Overview

Builds the rubydex graph index from Ruby source files.

Scans a project root for +.rb+ files, excluding common non-source directories, creates a graph, indexes all matching files, and resolves references.

Constant Summary collapse

EXCLUDED_DIRS =
%w[node_modules tmp log vendor .git .bundle].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_index(root) ⇒ Object



22
23
24
25
26
27
# File 'lib/rails_ai_bridge/rubydex_adapter/indexer.rb', line 22

def self.build_index(root)
  graph = ::Rubydex::Graph.new
  index_files(graph, root)
  graph.resolve
  graph
end

.index_files(graph, root) ⇒ Object



29
30
31
# File 'lib/rails_ai_bridge/rubydex_adapter/indexer.rb', line 29

def self.index_files(graph, root)
  graph.index_all(source_files(root))
end

.source_files(root) ⇒ Array<String>

Collects all non-excluded Ruby source files under the project root.

Parameters:

  • root (String)

    the project root directory path

Returns:

  • (Array<String>)

    absolute file paths



37
38
39
40
41
42
43
# File 'lib/rails_ai_bridge/rubydex_adapter/indexer.rb', line 37

def self.source_files(root)
  root = File.expand_path(root)
  Dir.glob(File.join(root, '**', '*.rb')).reject do |path|
    components = path.sub("#{root}/", '').split('/')
    EXCLUDED_DIRS.intersect?(components)
  end
end

Instance Method Details

#build(root) ⇒ Rubydex::Graph

Builds and returns a resolved rubydex graph for the given root.

Parameters:

  • root (String)

    the project root directory path

Returns:

  • (Rubydex::Graph)

    indexed and resolved graph

Raises:

  • (StandardError)

    when indexing or resolving fails



18
19
20
# File 'lib/rails_ai_bridge/rubydex_adapter/indexer.rb', line 18

def build(root)
  self.class.build_index(root)
end