class RubyDetective::SourceRepresentation::Entities::Constant

Attributes

caller[R]
data_store[R]
file_path[R]
name[R]
namespace[R]
refers_to[R]

Public Class Methods

new(name, namespace, file_path:, caller:, refers_to: nil) click to toggle source
# 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

Public Instance Methods

caller_namespace() click to toggle source
# File lib/ruby_detective/source_representation/entities/constant.rb, line 16
def caller_namespace
  caller.namespace
end
possible_paths_of_referenced_entity() click to toggle source
# 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) click to toggle source
# File lib/ruby_detective/source_representation/entities/constant.rb, line 20
def register_referred_class(klass)
  @refers_to = klass
end

Private Instance Methods

possible_parent_namespaces() click to toggle source
# File lib/ruby_detective/source_representation/entities/constant.rb, line 37
def possible_parent_namespaces
  (caller_namespace.size - 1)
  .downto(0)
  .map { |i| caller_namespace[0..i] }
end