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

Extended by:
T::Sig, Reflection, Tracker
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.

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, Reflection::SignatureBlockError, Reflection::UNDEFINED_CONSTANT

Class Method Summary collapse

Methods included from Tracker

disable!, enabled?, extended, with_disabled_tracker

Methods included from Reflection

abstract_type_of, ancestors_of, are_equal?, class_of, const_source_location, constant_defined?, constantize, constants_of, descendants_of, file_candidates_for, final_module?, 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, sealed_module?, signature_of, signature_of!, singleton_class_of, superclass_of

Methods included from AttachedClassOf

#attached_class_of

Class Method Details

.build_source_location(tp, locations) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 61

def build_source_location(tp, locations)
  loc = resolve_loc(locations)
  file = loc&.file
  line = loc&.line
  lineno = file && File.identical?(file, tp.path) ? tp.lineno : (line || 0)

  SourceLocation.from_loc([file || "", lineno])
end

.disable!Object



55
56
57
58
59
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 55

def disable!
  @class_tracepoint.disable
  @creturn_tracepoint.disable
  super
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 requireing, or where metaprogramming was used via eval, etc. : (Module klass) -> Set



74
75
76
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 74

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

.locations_for(klass) ⇒ Object

: (Module klass) -> Set



79
80
81
# File 'lib/tapioca/runtime/trackers/constant_definition.rb', line 79

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