Class: Holistic::Ruby::Scope::Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepository

Returns a new instance of Repository.



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

def initialize
  @table = ::Holistic::Database::Table.new(primary_attribute: :fully_qualified_name, indices: [:file_paths])
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#delete_by_fully_qualified_name(fully_qualified_name) ⇒ Object



41
42
43
# File 'lib/holistic/ruby/scope/repository.rb', line 41

def delete_by_fully_qualified_name(fully_qualified_name)
  table.delete(fully_qualified_name)
end

#find_by_cursor(cursor) ⇒ Object



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

def find_by_cursor(cursor)
  table.filter(:file_paths, cursor.file_path).map { _1[:scope] }.each do |scope|
    return scope if scope.locations.any? { _1.declaration.contains?(cursor) }
  end

  nil
end

#find_by_fully_qualified_name(fully_qualified_name) ⇒ Object



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

def find_by_fully_qualified_name(fully_qualified_name)
  table.find(fully_qualified_name).try(:dig, :scope)
end

#find_inner_most_scope_by_cursor(cursor) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/holistic/ruby/scope/repository.rb', line 31

def find_inner_most_scope_by_cursor(cursor)
  scopes = table.filter(:file_paths, cursor.file_path).map { _1[:scope] }

  matching_scopes = scopes.filter do |scope|
    scope.locations.any? { _1.body.contains?(cursor) }
  end

  matching_scopes.last
end

#list_scopes_in_file(file_path) ⇒ Object



45
46
47
# File 'lib/holistic/ruby/scope/repository.rb', line 45

def list_scopes_in_file(file_path)
  table.filter(:file_paths, file_path).map { _1[:scope] }
end

#register_scope(scope) ⇒ Object



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

def register_scope(scope)
  table.update({
    fully_qualified_name: scope.fully_qualified_name,
    file_paths: scope.locations.map { |scope_location| scope_location.declaration.file_path },
    scope:
  })
end