Class: Spoom::Deadcode::Index
- Inherits:
-
Object
- Object
- Spoom::Deadcode::Index
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/deadcode/index.rb
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Instance Method Summary collapse
- #all_definitions ⇒ Object
- #all_references ⇒ Object
- #define(definition) ⇒ Object
- #definitions_for_name(name) ⇒ Object
- #finalize! ⇒ Object
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #reference(reference) ⇒ Object
Constructor Details
#initialize ⇒ Index
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
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
10 11 12 |
# File 'lib/spoom/deadcode/index.rb', line 10 def definitions @definitions end |
#references ⇒ Object (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_definitions ⇒ Object
51 52 53 |
# File 'lib/spoom/deadcode/index.rb', line 51 def all_definitions @definitions.values.flatten end |
#all_references ⇒ Object
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 |