Skip to content

Commit

Permalink
Safely load gem plugin. Avoid stackoverflow if other versions of YARD…
Browse files Browse the repository at this point in the history
… are present.
  • Loading branch information
lsegal committed Oct 19, 2009
1 parent cd5d562 commit 3ebb560
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/rubygems_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def has_yardoc
@has_rdoc == 'yard'
end

undef has_rdoc? # redefining
def has_rdoc?
@has_rdoc && @has_rdoc != 'yard'
end
Expand Down Expand Up @@ -43,18 +42,16 @@ def run_yardoc(*args)
rescue Errno::EACCES => e
dirname = File.dirname e.message.split("-")[1].strip
raise Gem::FilePermissionError.new(dirname)
rescue RuntimeError => ex
rescue => ex
alert_error "While generating documentation for #{@spec.full_name}"
ui.errs.puts "... MESSAGE: #{ex}"
ui.errs.puts "... YARDDOC args: #{args.join(' ')}"
ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
Gem.configuration.backtrace
ui.errs.puts "\t#{ex.backtrace.join("\n\t")}" if Gem.configuration.backtrace
ui.errs.puts "(continuing with the rest of the installation)"
ensure
Dir.chdir(old_pwd)
end

undef setup_rdoc # redefining
def setup_rdoc
if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
raise Gem::FilePermissionError.new(@doc_dir)
Expand All @@ -75,21 +72,21 @@ def install_yardoc
run_yardoc '-o', rdoc_dir
end

def install_ri_yard
@@install_ri_yard_orig.bind(self).call if @spec.has_rdoc?
end
@@install_ri_yard_orig = instance_method(:install_ri)
undef install_ri # redefining
alias install_ri install_ri_yard

def install_rdoc_yard
if @spec.has_rdoc?
@@install_rdoc_yard_orig.bind(self).call
elsif @spec.has_yardoc?
install_yardoc
unless instance_methods.include?(:install_ri_yard)
def install_ri_yard
install_ri_yard_orig if @spec.has_rdoc?
end
alias install_ri_yard_orig install_ri
alias install_ri install_ri_yard

def install_rdoc_yard
if @spec.has_rdoc?
install_rdoc_yard_orig
elsif @spec.has_yardoc?
install_yardoc
end
end
alias install_rdoc_yard_orig install_rdoc
alias install_rdoc install_rdoc_yard
end
@@install_rdoc_yard_orig = instance_method(:install_rdoc)
undef install_rdoc # redefining
alias install_rdoc install_rdoc_yard
end

0 comments on commit 3ebb560

Please sign in to comment.