Class: Holistic::Ruby::Reference::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/holistic/ruby/reference/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database:) ⇒ Repository

Returns a new instance of Repository.



7
8
9
# File 'lib/holistic/ruby/reference/repository.rb', line 7

def initialize(database:)
  @database = database
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



5
6
7
# File 'lib/holistic/ruby/reference/repository.rb', line 5

def database
  @database
end

Instance Method Details

#find_by_cursor(cursor) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/holistic/ruby/reference/repository.rb', line 11

def find_by_cursor(cursor)
  @database.find(cursor.file_path)&.then do |file|
    file.defines_references.find do |reference|
      reference.location.contains?(cursor)
    end
  end
end

#list_references_in_file(file_path) ⇒ Object



19
20
21
# File 'lib/holistic/ruby/reference/repository.rb', line 19

def list_references_in_file(file_path)
  @database.find(file_path)&.defines_references || []
end

#list_references_to_scopes_in_file(scopes:, file_path:) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/holistic/ruby/reference/repository.rb', line 23

def list_references_to_scopes_in_file(scopes:, file_path:)
  references = @database.find(file_path)&.defines_scopes&.flat_map do |scope|
    scope.referenced_by.to_a
  end

  references || []
end