Class: Steep::Index::SourceIndex::ConstantEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/index/source_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ ConstantEntry

Returns a new instance of ConstantEntry.



10
11
12
13
14
15
# File 'lib/steep/index/source_index.rb', line 10

def initialize(name:)
  @name = name

  @definitions = Set[].compare_by_identity
  @references = Set[].compare_by_identity
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



7
8
9
# File 'lib/steep/index/source_index.rb', line 7

def definitions
  @definitions
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/steep/index/source_index.rb', line 5

def name
  @name
end

#referencesObject (readonly)

Returns the value of attribute references.



8
9
10
# File 'lib/steep/index/source_index.rb', line 8

def references
  @references
end

Instance Method Details

#add_definition(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/steep/index/source_index.rb', line 17

def add_definition(node)
  case node.type
  when :casgn, :const
    @definitions << node
  else
    raise "Unexpected constant definition: #{node.type}"
  end

  self
end

#add_reference(node) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/steep/index/source_index.rb', line 28

def add_reference(node)
  case node.type
  when :const
    @references << node
  else
    raise "Unexpected constant reference: #{node.type}"
  end

  self
end

#merge!(other) ⇒ Object



39
40
41
42
43
# File 'lib/steep/index/source_index.rb', line 39

def merge!(other)
  definitions.merge(other.definitions)
  references.merge(other.references)
  self
end