Class: YARD::RubygemsHook
- Inherits:
-
Object
- Object
- YARD::RubygemsHook
- Extended by:
- Gem::UserInteraction
- Includes:
- Gem::UserInteraction
- Defined in:
- lib/yard/rubygems/hook.rb
Class Attribute Summary collapse
-
.yard_version ⇒ Object
readonly
Loaded version of YARD.
Instance Attribute Summary collapse
-
#force ⇒ Object
Force installation of documentation?.
-
#generate_yard ⇒ Object
Generate yard?.
-
#generate_yri ⇒ Object
Generate yri data?.
Class Method Summary collapse
-
.generation_hook(installer, specs) ⇒ Object
Post installs hook that generates documentation for each specification in
specs
. -
.load_yard ⇒ Object
Loads the YARD generator.
-
.removal_hook(uninstaller) ⇒ Object
Pre uninstalls hook that removes documentation.
Instance Method Summary collapse
-
#generate ⇒ Object
Generates YARD and yri data.
-
#initialize(spec, generate_yard = false, generate_yri = true) ⇒ RubygemsHook
constructor
A new instance of RubygemsHook.
- #install_yard ⇒ Object
- #install_yri ⇒ Object
-
#remove ⇒ Object
Removes YARD and yri data.
- #run_yardoc(*args) ⇒ Object
-
#setup ⇒ Object
Prepares the spec for documentation generation.
- #uninstall_yard ⇒ Object
- #uninstall_yri ⇒ Object
Constructor Details
#initialize(spec, generate_yard = false, generate_yri = true) ⇒ RubygemsHook
Returns a new instance of RubygemsHook.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/yard/rubygems/hook.rb', line 93 def initialize(spec, generate_yard = false, generate_yri = true) @doc_dir = spec.doc_dir @force = false @spec = spec @generate_yard = generate_yard @generate_yri = generate_yri @yard_dir = spec.doc_dir('yard') @yri_dir = spec.doc_dir('.yardoc') end |
Class Attribute Details
.yard_version ⇒ Object (readonly)
Loaded version of YARD. Set by ::load_yard
38 39 40 |
# File 'lib/yard/rubygems/hook.rb', line 38 def yard_version @yard_version end |
Instance Attribute Details
#force ⇒ Object
Force installation of documentation?
22 23 24 |
# File 'lib/yard/rubygems/hook.rb', line 22 def force @force end |
#generate_yard ⇒ Object
Generate yard?
27 28 29 |
# File 'lib/yard/rubygems/hook.rb', line 27 def generate_yard @generate_yard end |
#generate_yri ⇒ Object
Generate yri data?
32 33 34 |
# File 'lib/yard/rubygems/hook.rb', line 32 def generate_yri @generate_yri end |
Class Method Details
.generation_hook(installer, specs) ⇒ Object
Post installs hook that generates documentation for each specification in specs
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yard/rubygems/hook.rb', line 45 def self.generation_hook(installer, specs) start = Time.now types = installer.document generate_yard = types.include?('yardoc') || types.include?('yard') generate_yri = types.include? 'yri' specs.each do |spec| gen_yard = generate_yard gen_yri = generate_yri gen_yri = false if gen_yard # never generate both, no need unless types.empty? # --no-document is not in effect # look at spec.metadata['yard.run'] for override run_yard = spec.['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 || generate_yri duration = (Time.now - start).to_i names = specs.map(&:name).join ', ' say "Done installing documentation for #{names} after #{duration} seconds" end |
.load_yard ⇒ Object
Loads the YARD generator
85 86 87 88 89 90 91 |
# File 'lib/yard/rubygems/hook.rb', line 85 def self.load_yard return if @yard_version require 'yard' @yard_version = Gem::Version.new ::YARD::VERSION end |
.removal_hook(uninstaller) ⇒ Object
Pre uninstalls hook that removes documentation
78 79 80 |
# File 'lib/yard/rubygems/hook.rb', line 78 def self.removal_hook(uninstaller) new(uninstaller.spec).remove end |
Instance Method Details
#generate ⇒ Object
Generates YARD and yri data
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/yard/rubygems/hook.rb', line 148 def generate return if @spec.default_gem? return unless @generate_yri || @generate_yard setup install_yri if @generate_yri && (@force || !File.exist?(@yri_dir)) install_yard if @generate_yard && (@force || !File.exist?(@yard_dir)) end |
#install_yard ⇒ Object
131 132 133 134 135 136 |
# File 'lib/yard/rubygems/hook.rb', line 131 def install_yard FileUtils.rm_rf @yard_dir say "Installing YARD documentation for #{@spec.full_name}..." run_yardoc '--no-progress', '--db', @yri_dir, '-o', @yard_dir end |
#install_yri ⇒ Object
138 139 140 141 142 143 |
# File 'lib/yard/rubygems/hook.rb', line 138 def install_yri FileUtils.rm_rf @yri_dir say "Building YARD (yri) index for #{@spec.full_name}..." run_yardoc '--no-progress', '-c', '-n', '--db', @yri_dir end |
#remove ⇒ Object
Removes YARD and yri data
189 190 191 192 |
# File 'lib/yard/rubygems/hook.rb', line 189 def remove uninstall_yri uninstall_yard end |
#run_yardoc(*args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/yard/rubygems/hook.rb', line 105 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 unless @spec.extra_rdoc_files.empty? args << '-' args += @spec.extra_rdoc_files end end 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..split("-")[1].strip 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 ui.errs.puts "(continuing with the rest of the installation)" end |
#setup ⇒ Object
Prepares the spec for documentation generation
162 163 164 165 166 167 168 169 170 |
# File 'lib/yard/rubygems/hook.rb', line 162 def setup self.class.load_yard if File.exist?(@doc_dir) raise Gem::FilePermissionError, @doc_dir unless File.writable?(@doc_dir) else FileUtils.mkdir_p @doc_dir end end |