ruby-changes:67538
From: aycabta <ko1@a...>
Date: Thu, 2 Sep 2021 00:32:28 +0900 (JST)
Subject: [ruby-changes:67538] cf2faf2e33 (master): [ruby/rdoc] Move RDoc::RDoc#load_options to RDoc::RDoc.load_options
https://git.ruby-lang.org/ruby.git/commit/?id=cf2faf2e33 From cf2faf2e3336592dbc9b94e8189f62e99cc9ae0c Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> 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 +++++++++++++++++++++ lib/rdoc/rdoc.rb | 33 ++---------------------- test/rdoc/test_rdoc_options.rb | 58 ++++++++++++++++++++++++++++++++++++++++++ test/rdoc/test_rdoc_rdoc.rb | 58 ------------------------------------------ 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 13b7ba5..7a45a9c 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -1282,4 +1282,33 @@ Usage: #{opt.program_name} [options] [names...] https://github.com/ruby/ruby/blob/trunk/lib/rdoc/options.rb#L1282 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 diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 3a3defa..5255e04 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -14,7 +14,7 @@ require 'time' https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rdoc.rb#L14 # is: # # rdoc = RDoc::RDoc.new -# options = rdoc.load_options # returns an RDoc::Options instance +# options = RDoc::Options.load_options # returns an RDoc::Options instance # # set extra options # rdoc.document options # @@ -152,35 +152,6 @@ class RDoc::RDoc https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rdoc.rb#L152 end ## - # Loads options from .rdoc_options if the file exists, otherwise creates a - # new RDoc::Options instance. - - def 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 - - ## # Create an output dir if it doesn't exist. If it does exist, but doesn't # contain the flag file <tt>created.rid</tt> then we refuse to use it, as # we may clobber some manually generated documentation @@ -471,7 +442,7 @@ The internal error was: https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rdoc.rb#L442 @options = options @options.finish else - @options = load_options + @options = RDoc::Options.load_options @options.parse options end diff --git a/test/rdoc/test_rdoc_options.rb b/test/rdoc/test_rdoc_options.rb index f547f5b..206ddee 100644 --- a/test/rdoc/test_rdoc_options.rb +++ b/test/rdoc/test_rdoc_options.rb @@ -777,4 +777,62 @@ rdoc_include: https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_options.rb#L777 @options.visibility = :all assert_equal :private, @options.visibility end + + def test_load_options + temp_dir do + options = RDoc::Options.new + options.markup = 'tomdoc' + options.write_options + + options = RDoc::Options.load_options + + assert_equal 'tomdoc', options.markup + end + end + + def test_load_options_invalid + temp_dir do + File.open '.rdoc_options', 'w' do |io| + io.write "a: !ruby.yaml.org,2002:str |\nfoo" + end + + e = assert_raise RDoc::Error do + RDoc::Options.load_options + end + + options_file = File.expand_path '.rdoc_options' + assert_equal "#{options_file} is not a valid rdoc options file", e.message + end + end + + def test_load_options_empty_file + temp_dir do + File.open '.rdoc_options', 'w' do |io| + end + + options = RDoc::Options.load_options + + assert_equal 'rdoc', options.markup + end + end + + def test_load_options_partial_override + temp_dir do + File.open '.rdoc_options', 'w' do |io| + io.write "markup: Markdown" + end + + options = RDoc::Options.load_options + + assert_equal 'Markdown', options.markup + end + end + + def load_options_no_file + temp_dir do + options = RDoc::Options.load_options + + assert_kind_of RDoc::Options, options + end + end end diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index bb45735..eaf92c8 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -106,64 +106,6 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L106 $stdin = STDIN end - def test_load_options - temp_dir do - options = RDoc::Options.new - options.markup = 'tomdoc' - options.write_options - - options = @rdoc.load_options - - assert_equal 'tomdoc', options.markup - end - end - - def test_load_options_invalid - temp_dir do - File.open '.rdoc_options', 'w' do |io| - io.write "a: !ruby.yaml.org,2002:str |\nfoo" - end - - e = assert_raise RDoc::Error do - @rdoc.load_options - end - - options_file = File.expand_path '.rdoc_options' - assert_equal "#{options_file} is not a valid rdoc options file", e.message - end - end - - def test_load_options_empty_file - temp_dir do - File.open '.rdoc_options', 'w' do |io| - end - - options = @rdoc.load_options - - assert_equal 'rdoc', options.markup - end - end - - def test_load_options_partial_override - temp_dir do - File.open '.rdoc_options', 'w' do |io| - io.write "markup: Markdown" - end - - options = @rdoc.load_options - - assert_equal 'Markdown', options.markup - end - end - - def load_options_no_file - temp_dir do - options = @rdoc.load_options - - assert_kind_of RDoc::Options, options - end - end - def test_normalized_file_list test_path = File.expand_path(__FILE__) files = temp_dir do |dir| -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/