Module: Tapioca::Runtime::Trackers::ConstantDefinition

Extended by:
T::Sig, Reflection
Defined in:
lib/tapioca/runtime/trackers/constant_definition.rb

Overview

Registers a TracePoint immediately upon load to track points at which classes and modules are opened for definition. This is used to track correspondence between classes/modules and files, as this information isn't available in the ruby runtime without extra accounting.

Defined Under Namespace

Classes: ConstantLocation

Constant Summary

Constants included from Reflection

Reflection::ANCESTORS_METHOD, Reflection::CLASS_METHOD, Reflection::CONSTANTS_METHOD, Reflection::EQUAL_METHOD, Reflection::METHOD_METHOD, Reflection::NAME_METHOD, Reflection::OBJECT_ID_METHOD, Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Reflection::REQUIRED_FROM_LABELS, Reflection::SINGLETON_CLASS_METHOD, Reflection::SUPERCLASS_METHOD

Class Method Summary collapse

Methods included from Reflection

ancestors_of, are_equal?, class_of, constant_from_singleton_class, constant_name_from_singleton_class, constantize, constants_of, descendants_of, inherited_ancestors_of, method_of, name_of, name_of_type, object_id_of, private_instance_methods_of, protected_instance_methods_of, public_instance_methods_of, qualified_name_of, resolve_loc, signature_of, singleton_class_of, superclass_of

Class Method Details

.build_constant_location(tp, locations) ⇒ Object



52
53
54
55
56
57
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 52

def self.build_constant_location(tp, locations)
  file = resolve_loc(caller_locations)
  lineno = file == File.realpath(tp.path) ? tp.lineno : 0

  ConstantLocation.new(path: file, lineno: lineno)
end

.files_for(klass) ⇒ Object

Returns the files in which this class or module was opened. Doesn't know about situations where the class was opened prior to +require+ing, or where metaprogramming was used via eval, etc.



62
63
64
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 62

def self.files_for(klass)
  locations_for(klass).map(&:path).to_set
end

.locations_for(klass) ⇒ Object



66
67
68
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 66

def self.locations_for(klass)
  @class_files.fetch(klass, Set.new)
end