Skip to content

Commit

Permalink
pry_ext/method_info: refactor .parse_and_cache_if_gem_cext
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Dec 30, 2016
1 parent 07e269a commit c036fc1
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/pry-doc/pry_ext/method_info.rb
Original file line number Diff line number Diff line change
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

0 comments on commit c036fc1

Please sign in to comment.