lib/tapioca/constant_locator.rb in tapioca-0.4.27 vs lib/tapioca/constant_locator.rb in tapioca-0.5.0

- old
+ new

@@ -1,36 +1,34 @@ # typed: true # frozen_string_literal: true -require 'set' +require "set" module Tapioca # 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. module ConstantLocator + extend Reflection + @class_files = {} - NAME = Module.instance_method(:name) - private_constant :NAME - # Immediately activated upon load. Observes class/module definition. TracePoint.trace(:class) do |tp| unless tp.self.singleton_class? - key = NAME.bind(tp.self).call + key = name_of(tp.self) @class_files[key] ||= Set.new @class_files[key] << tp.path end end # 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. - def files_for(klass) - name = String === klass ? klass : NAME.bind(klass).call + def self.files_for(klass) + name = String === klass ? klass : name_of(klass) files = @class_files[name] files || Set.new end - module_function :files_for end end