Module: Holistic::Ruby::Scope::Delete

Extended by:
Delete
Included in:
Delete
Defined in:
lib/holistic/ruby/scope/delete.rb

Instance Method Summary collapse

Instance Method Details

#call(database:, fully_qualified_name:, file_path:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/holistic/ruby/scope/delete.rb', line 7

def call(database:, fully_qualified_name:, file_path:)
  scope = database.find(fully_qualified_name)

  return :scope_not_found if scope.nil?

  location_to_remove = scope.locations.find { |scope_location| scope_location.declaration.file.path == file_path }

  return :scope_not_defined_in_speciefied_file if location_to_remove.nil?

  scope.locations.delete(location_to_remove)

  scope.relation(:scope_defined_in_file).delete!(location_to_remove.declaration.file)

  if scope.locations.empty?
    scope.relation(:lexical_parent).delete!(scope.lexical_parent)

    database.delete(fully_qualified_name)
  end

  :definition_unregistered
end