-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: use a
MethodDefinition
tracker to properly attribute methods d…
…efinitions that are triggered by one gem but defined in another
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
module Tapioca | ||
module Runtime | ||
module Trackers | ||
module MethodDefinition | ||
extend Tracker | ||
extend T::Sig | ||
|
||
@method_definitions = {}.compare_by_identity | ||
|
||
class << self | ||
extend T::Sig | ||
|
||
sig { params(constant: Module, method_name: Symbol).void } | ||
def register(constant, method_name) | ||
return unless enabled? | ||
|
||
@method_definitions[constant] ||= {} | ||
@method_definitions[constant][method_name] = Reflection.resolve_loc(caller_locations) | ||
end | ||
|
||
sig { params(constant: Module).returns(T::Hash[Symbol, T::Array[T::Hash[Symbol, String]]]) } | ||
def method_definitions_for(constant) | ||
@method_definitions[constant] || {} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Module | ||
prepend(Module.new do | ||
def method_added(method_name) | ||
Tapioca::Runtime::Trackers::MethodDefinition.register(self, method_name) | ||
super | ||
end | ||
end) | ||
end | ||
|
||
# TODO: are there other methods I have to override here? |