Class: RubyDetective::SourceRepresentation::Entities::Constant

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_detective/source_representation/entities/constant.rb

Constant Summary

Constants inherited from Base

Base::ROOT_SIGN_SYMBOL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#absolute_path?, #namespace_as_text, #namespace_without_root_sign, #path, #path_as_text, #path_without_root_sign

Constructor Details

#initialize(name, namespace, file_path:, caller:, refers_to: nil) ⇒ Constant

Returns a new instance of Constant.



7
8
9
10
11
12
13
14
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 7

def initialize(name, namespace, file_path:, caller:, refers_to: nil)
  @name = name
  @namespace = namespace
  @file_path = file_path
  @refers_to = refers_to
  @caller = caller
  @data_store = SourceRepresentation::DataStore.instance
end

Instance Attribute Details

#callerObject (readonly)

Returns the value of attribute caller.



5
6
7
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 5

def caller
  @caller
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 5

def file_path
  @file_path
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 5

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 5

def namespace
  @namespace
end

#refers_toObject (readonly)

Returns the value of attribute refers_to.



5
6
7
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 5

def refers_to
  @refers_to
end

Instance Method Details

#caller_namespaceObject



16
17
18
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 16

def caller_namespace
  caller.namespace
end

#possible_paths_of_referenced_entityObject



24
25
26
27
28
29
30
31
32
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 24

def possible_paths_of_referenced_entity
  # If the constant was like "::Foo::Bar" there is only one possible
  # match: the exact path described in the constant
  return [path_without_root_sign] if absolute_path?

  possible_parent_namespaces
  .map { |possible_parent| possible_parent + path }
  .push(path)
end

#register_referred_class(klass) ⇒ Object



20
21
22
# File 'lib/ruby_detective/source_representation/entities/constant.rb', line 20

def register_referred_class(klass)
  @refers_to = klass
end