Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pry_ext/method_info: refactor .parse_and_cache_if_gem_cext #58

Merged
merged 1 commit into from Dec 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/pry-doc/pry_ext/method_info.rb
Expand Up @@ -58,23 +58,19 @@ def self.info_for(meth)
registry_lookup(meth)
end

##
# Attempts to find the c source files if method belongs to a gem
# and use YARD to parse and cache the source files for display
#
# @param [Method, UnboundMethod] meth The method object.
def self.parse_and_cache_if_gem_cext(meth)
if gem_dir = find_gem_dir(meth)
if c_files_found?(gem_dir)
warn "Scanning and caching *.c files..."
YARD.parse("#{gem_dir}/**/*.c")
end
end
end
return unless (gem_dir = find_gem_dir(meth))

path = "#{gem_dir}/**/*.c"
return if Dir.glob(path).none?

# @param [String] root directory path of gem that method belongs to
# @return [Boolean] true if c files exist?
def self.c_files_found?(gem_dir)
Dir.glob("#{gem_dir}/**/*.c").count > 0
puts "Scanning and caching *.c files..."
YARD.parse(path)
end

# @return [Object] The host of the method (receiver or owner).
Expand Down