Class: OllamaAgent::RubyIndex::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/ruby_index/index.rb

Overview

Immutable snapshot of class/module and method definitions for a tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, constants:, methods:, errors:, files_indexed:) ⇒ Index

Returns a new instance of Index.



9
10
11
12
13
14
15
# File 'lib/ollama_agent/ruby_index/index.rb', line 9

def initialize(root:, constants:, methods:, errors:, files_indexed:)
  @root = root
  @constants = constants.freeze
  @methods = methods.freeze
  @errors = errors.freeze
  @files_indexed = files_indexed
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



7
8
9
# File 'lib/ollama_agent/ruby_index/index.rb', line 7

def constants
  @constants
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/ollama_agent/ruby_index/index.rb', line 7

def errors
  @errors
end

#files_indexedObject (readonly)

Returns the value of attribute files_indexed.



7
8
9
# File 'lib/ollama_agent/ruby_index/index.rb', line 7

def files_indexed
  @files_indexed
end

#methodsObject (readonly)

Returns the value of attribute methods.



7
8
9
# File 'lib/ollama_agent/ruby_index/index.rb', line 7

def methods
  @methods
end

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/ollama_agent/ruby_index/index.rb', line 7

def root
  @root
end

Instance Method Details

#search_class(pattern) ⇒ Object



17
18
19
# File 'lib/ollama_agent/ruby_index/index.rb', line 17

def search_class(pattern)
  match_records(@constants.select { |r| r[:kind] == :class }, pattern)
end

#search_class_or_module(pattern) ⇒ Object



25
26
27
# File 'lib/ollama_agent/ruby_index/index.rb', line 25

def search_class_or_module(pattern)
  match_records(@constants, pattern)
end

#search_method(pattern) ⇒ Object



29
30
31
# File 'lib/ollama_agent/ruby_index/index.rb', line 29

def search_method(pattern)
  match_records(@methods, pattern, field: :name)
end

#search_module(pattern) ⇒ Object



21
22
23
# File 'lib/ollama_agent/ruby_index/index.rb', line 21

def search_module(pattern)
  match_records(@constants.select { |r| r[:kind] == :module }, pattern)
end

#summary_lineObject



33
34
35
36
# File 'lib/ollama_agent/ruby_index/index.rb', line 33

def summary_line
  "ruby_index: #{@files_indexed} files, #{@constants.size} classes/modules, #{@methods.size} methods" \
    "#{", #{@errors.size} parse warning(s)" unless errors.empty?}"
end