From cf2faf2e3336592dbc9b94e8189f62e99cc9ae0c Mon Sep 17 00:00:00 2001 From: aycabta Date: Thu, 2 Sep 2021 00:21:10 +0900 Subject: [ruby/rdoc] Move RDoc::RDoc#load_options to RDoc::RDoc.load_options https://github.com/ruby/rdoc/commit/ac85e01756 --- lib/rdoc/options.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/rdoc/options.rb') diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 13b7ba5c6c..7a45a9c610 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -1282,4 +1282,33 @@ Usage: #{opt.program_name} [options] [names...] end end + ## + # Loads options from .rdoc_options if the file exists, otherwise creates a + # new RDoc::Options instance. + + def self.load_options + options_file = File.expand_path '.rdoc_options' + return RDoc::Options.new unless File.exist? options_file + + RDoc.load_yaml + + begin + options = YAML.safe_load File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol] + rescue Psych::SyntaxError + raise RDoc::Error, "#{options_file} is not a valid rdoc options file" + end + + return RDoc::Options.new unless options # Allow empty file. + + raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless + RDoc::Options === options or Hash === options + + if Hash === options + # Override the default values with the contents of YAML file. + options = RDoc::Options.new options + end + + options + end + end -- cgit v1.2.3