lib/yard/rubygems/hook.rb in yard-0.9.5 vs lib/yard/rubygems/hook.rb in yard-0.9.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'rubygems' require 'rubygems/user_interaction' require 'fileutils' ## @@ -8,11 +9,10 @@ # # This file is automatically required by RubyGems 1.9 and newer. module YARD class RubygemsHook - include Gem::UserInteraction extend Gem::UserInteraction @yard_version = nil @@ -30,16 +30,14 @@ # Generate yri data? attr_accessor :generate_yri class << self - ## # Loaded version of YARD. Set by ::load_yard attr_reader :yard_version - end ## # Post installs hook that generates documentation for each specification in # +specs+ @@ -50,23 +48,24 @@ generate_yard = types.include?('yardoc') || types.include?('yard') generate_yri = types.include? 'yri' specs.each do |spec| - gen_yard, gen_yri = generate_yard, generate_yri + gen_yard = generate_yard + gen_yri = generate_yri gen_yri = false if gen_yard # never generate both, no need - if types.size > 0 # --no-document is not in effect + unless types.empty? # --no-document is not in effect # look at spec.metadata['yard.run'] for override run_yard = spec.metadata['yard.run'] gen_yard = true if run_yard && run_yard != 'yri' gen_yri = true if run_yard == 'yri' end new(spec, gen_yard, gen_yri).generate end - return unless generate_yard or generate_yri + return unless generate_yard || generate_yri duration = (Time.now - start).to_i names = specs.map(&:name).join ', ' say "Done installing documentation for #{names} after #{duration} seconds" @@ -98,23 +97,23 @@ def run_yardoc(*args) args << '--quiet' unless Gem.configuration.really_verbose args << '--backtrace' if Gem.configuration.backtrace unless File.file?(File.join(@spec.full_gem_path, '.yardopts')) args << @spec.require_paths - if @spec.extra_rdoc_files.size > 0 + unless @spec.extra_rdoc_files.empty? args << '-' args += @spec.extra_rdoc_files end end - args = args.flatten.map {|arg| arg.to_s } + args = args.flatten.map(&:to_s) Dir.chdir(@spec.full_gem_path) do YARD::CLI::Yardoc.run(*args) end rescue Errno::EACCES => e dirname = File.dirname e.message.split("-")[1].strip - raise Gem::FilePermissionError.new(dirname) + raise Gem::FilePermissionError, dirname rescue => ex alert_error "While generating documentation for #{@spec.full_name}" ui.errs.puts "... MESSAGE: #{ex}" ui.errs.puts "... YARDOC args: #{args.join(' ')}" ui.errs.puts "\t#{ex.backtrace.join("\n\t")}" if Gem.configuration.backtrace @@ -142,28 +141,22 @@ return if @spec.default_gem? return unless @generate_yri || @generate_yard setup - if @generate_yri && (@force || !File.exist?(@yri_dir)) - install_yri - end + install_yri if @generate_yri && (@force || !File.exist?(@yri_dir)) - if @generate_yard && (@force || !File.exist?(@yard_dir)) - install_yard - end + install_yard if @generate_yard && (@force || !File.exist?(@yard_dir)) end ## # Prepares the spec for documentation generation def setup self.class.load_yard if File.exist?(@doc_dir) - unless File.writable?(@doc_dir) - raise Gem::FilePermissionError, @doc_dir - end + raise Gem::FilePermissionError, @doc_dir unless File.writable?(@doc_dir) else FileUtils.mkdir_p @doc_dir end end end