开发者

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 开发者_StackOverflow中文版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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜