简体   繁体   中英

How to exclude some classes from rdoc and ri generation during a gem installation in ruby?

I have written this gem that has more than 10,000 generated classes. While installing this gem it takes forever to install the ri and rdoc.

I know that I can disable ri and rdoc installation by passing --no-ri and --no-rdoc to gem install command but what I need to do is to somehow during the gem build process specify a list of rb files and then exclude the rest.

I want gem install command to automatically generate ri and rdoc only for those files.

I tried

Rake::RDocTask.new do |rdoc|
  files =['README.rdoc', 'LICENSE', 'lib/myclass.rb']
  rdoc.rdoc_files.add(files)
  rdoc.main = "README.rdoc" # page to start on
  rdoc.title = "mobilesrepo Docs"
  rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
  rdoc.options << '--line-numbers'
end

to only include myclass.rb for rdoc and ri generation but still the gem install command tries to generate rdoc and ri for all my *.rb files.

Any help would be appreciated.

The Rake::RDocTask task has nothing to do with rubygems. Your code will just generate html with

% rake rdoc

command in the doc/rdoc project directory.

To limit the scope for rdoc during the gem installation process, edit the specification for your gem:

require 'rake/gempackagetask'
spec = Gem::Specification.new {|i|
  ...
  i.rdoc_options += ['-m', 'README.rdoc', '-x', 'lib/(?!myclass.rb).*',
                     'lib/myclass.rb', 'LICENSE', 'README.rdoc']
  i.extra_rdoc_files = []
  ...
}

Rake::GemPackageTask.new(spec).define

The strange regular expression lib/(?!myclass.rb).* is required, because rubygems automatically adds lib path for rdoc and we need to

  1. exclude it ( -x option);
  2. allow lib/myclass.rb file to survive.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM