Class: Spoom::Deadcode::Index

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/deadcode/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



16
17
18
19
# File 'lib/spoom/deadcode/index.rb', line 16

def initialize
  @definitions = T.let({}, T::Hash[String, T::Array[Definition]])
  @references = T.let({}, T::Hash[String, T::Array[Reference]])
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



10
11
12
# File 'lib/spoom/deadcode/index.rb', line 10

def definitions
  @definitions
end

#referencesObject (readonly)

Returns the value of attribute references.



13
14
15
# File 'lib/spoom/deadcode/index.rb', line 13

def references
  @references
end

Instance Method Details

#all_definitionsObject



51
52
53
# File 'lib/spoom/deadcode/index.rb', line 51

def all_definitions
  @definitions.values.flatten
end

#all_referencesObject



56
57
58
# File 'lib/spoom/deadcode/index.rb', line 56

def all_references
  @references.values.flatten
end

#define(definition) ⇒ Object



24
25
26
# File 'lib/spoom/deadcode/index.rb', line 24

def define(definition)
  (@definitions[definition.name] ||= []) << definition
end

#definitions_for_name(name) ⇒ Object



46
47
48
# File 'lib/spoom/deadcode/index.rb', line 46

def definitions_for_name(name)
  @definitions[name] || []
end

#finalize!Object



37
38
39
40
41
# File 'lib/spoom/deadcode/index.rb', line 37

def finalize!
  @references.keys.each do |name|
    definitions_for_name(name).each(&:alive!)
  end
end

#reference(reference) ⇒ Object



29
30
31
# File 'lib/spoom/deadcode/index.rb', line 29

def reference(reference)
  (@references[reference.name] ||= []) << reference
end