ruby-changes:65580
From: aycabta <ko1@a...>
Date: Tue, 16 Mar 2021 15:47:46 +0900 (JST)
Subject: [ruby-changes:65580] 971a0cd246 (master): [ruby/rdoc] Allow partial default values to be overridden with .rdoc_options
https://git.ruby-lang.org/ruby.git/commit/?id=971a0cd246 From 971a0cd246db6578e1ea8760a903e1a23e3681f3 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sun, 7 Mar 2021 10:13:14 +0900 Subject: [ruby/rdoc] Allow partial default values to be overridden with .rdoc_options https://github.com/ruby/rdoc/commit/e14800891f --- lib/rdoc/options.rb | 34 +++++++++++++++++++++++++++++++++- lib/rdoc/rdoc.rb | 7 ++++++- test/rdoc/test_rdoc_rdoc.rb | 12 ++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 13c1aba..13b7ba5 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -338,8 +338,9 @@ class RDoc::Options https://github.com/ruby/ruby/blob/trunk/lib/rdoc/options.rb#L338 attr_reader :visibility - def initialize # :nodoc: + def initialize loaded_options = nil # :nodoc: init_ivars + override loaded_options if loaded_options end def init_ivars # :nodoc: @@ -417,6 +418,37 @@ class RDoc::Options https://github.com/ruby/ruby/blob/trunk/lib/rdoc/options.rb#L418 init_with map end + def override map # :nodoc: + if map.has_key?('encoding') + encoding = map['encoding'] + @encoding = encoding ? Encoding.find(encoding) : encoding + end + + @charset = map['charset'] if map.has_key?('charset') + @exclude = map['exclude'] if map.has_key?('exclude') + @generator_name = map['generator_name'] if map.has_key?('generator_name') + @hyperlink_all = map['hyperlink_all'] if map.has_key?('hyperlink_all') + @line_numbers = map['line_numbers'] if map.has_key?('line_numbers') + @locale_name = map['locale_name'] if map.has_key?('locale_name') + @locale_dir = map['locale_dir'] if map.has_key?('locale_dir') + @main_page = map['main_page'] if map.has_key?('main_page') + @markup = map['markup'] if map.has_key?('markup') + @op_dir = map['op_dir'] if map.has_key?('op_dir') + @show_hash = map['show_hash'] if map.has_key?('show_hash') + @tab_width = map['tab_width'] if map.has_key?('tab_width') + @template_dir = map['template_dir'] if map.has_key?('template_dir') + @title = map['title'] if map.has_key?('title') + @visibility = map['visibility'] if map.has_key?('visibility') + @webcvs = map['webcvs'] if map.has_key?('webcvs') + + if map.has_key?('rdoc_include') + @rdoc_include = sanitize_path map['rdoc_include'] + end + if map.has_key?('static_path') + @static_path = sanitize_path map['static_path'] + end + end + def == other # :nodoc: self.class === other and @encoding == other.encoding and diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index 93e764c..c47f639 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -167,7 +167,12 @@ class RDoc::RDoc https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rdoc.rb#L167 end raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless - RDoc::Options === options + 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 diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb index f7d9b86..b54cec5 100644 --- a/test/rdoc/test_rdoc_rdoc.rb +++ b/test/rdoc/test_rdoc_rdoc.rb @@ -133,6 +133,18 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L133 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/