Fix source lookup for instrumented classes

Once I include DataMapper::Resource, which defines a lot of
additional methods in dm-core/support/hook.rb, the "popularity"
of my own source file ranks lower than first, so candidate(0)
returns the DataMapper source file.  However, none of the REs
returned by #class_regexes matches because my class is obviously
not defined there.

This fixes the problem by re-defining #primary_candidate so that
it filters out obviously invalid candidates.
This commit is contained in:
Uwe Stuehler 2013-05-13 01:37:14 +02:00
parent cc736cd777
commit 5342a65197
1 changed files with 6 additions and 5 deletions

View File

@ -300,12 +300,13 @@ class Pry
end
end
# @return [Pry::WrappedModule::Candidate] The candidate of rank 0,
# that is the 'monkey patch' of this module with the highest
# number of methods. It is considered the 'canonical' definition
# for the module.
# @return [Pry::WrappedModule::Candidate] The candidate with the
# highest rank, that is the 'monkey patch' of this module with the
# highest number of methods, which actually contains a source code
# line that declaes the module. It is considered the 'canonical'
# definition for the module.
def primary_candidate
@primary_candidate ||= candidate(0)
@primary_candidate ||= candidates.find { |c| c.file }
end
# @return [Array<Array<Pry::Method>>] The array of `Pry::Method` objects,