Skip to content

Commit a7fdc73

Browse files
authored
Separate patterns by --exclude option from defaults (#1251)
1 parent 8a367a9 commit a7fdc73

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

lib/rdoc/options.rb

+24-7
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,24 @@ class RDoc::Options
355355
# +--[no-]embed-mixins+ (Default is +false+.)
356356
attr_accessor :embed_mixins
357357

358+
##
359+
# Exclude the default patterns as well if true.
360+
attr_reader :apply_default_exclude
361+
358362
def initialize loaded_options = nil # :nodoc:
359363
init_ivars
360364
override loaded_options if loaded_options
361365
end
362366

367+
DEFAULT_EXCLUDE = %w[
368+
~\z \.orig\z \.rej\z \.bak\z
369+
\.gemspec\z
370+
]
371+
363372
def init_ivars # :nodoc:
364373
@dry_run = false
365374
@embed_mixins = false
366-
@exclude = %w[
367-
~\z \.orig\z \.rej\z \.bak\z
368-
\.gemspec\z
369-
]
375+
@exclude = []
370376
@files = nil
371377
@force_output = false
372378
@force_update = true
@@ -405,6 +411,7 @@ def init_ivars # :nodoc:
405411
@encoding = Encoding::UTF_8
406412
@charset = @encoding.name
407413
@skip_tests = true
414+
@apply_default_exclude = true
408415
end
409416

410417
def init_with map # :nodoc:
@@ -430,6 +437,7 @@ def init_with map # :nodoc:
430437
@title = map['title']
431438
@visibility = map['visibility']
432439
@webcvs = map['webcvs']
440+
@apply_default_exclude = map['apply_default_exclude']
433441

434442
@rdoc_include = sanitize_path map['rdoc_include']
435443
@static_path = sanitize_path map['static_path']
@@ -463,6 +471,7 @@ def override map # :nodoc:
463471
@title = map['title'] if map.has_key?('title')
464472
@visibility = map['visibility'] if map.has_key?('visibility')
465473
@webcvs = map['webcvs'] if map.has_key?('webcvs')
474+
@apply_default_exclude = map['apply_default_exclude'] if map.has_key?('apply_default_exclude')
466475

467476
@warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref')
468477

@@ -493,7 +502,8 @@ def == other # :nodoc:
493502
@template == other.template and
494503
@title == other.title and
495504
@visibility == other.visibility and
496-
@webcvs == other.webcvs
505+
@webcvs == other.webcvs and
506+
@apply_default_exclude == other.apply_default_exclude
497507
end
498508

499509
##
@@ -564,10 +574,12 @@ def exclude
564574
if @exclude.nil? or Regexp === @exclude then
565575
# done, #finish is being re-run
566576
@exclude
567-
elsif @exclude.empty? then
577+
elsif !@apply_default_exclude and @exclude.empty? then
568578
nil
569579
else
570-
Regexp.new(@exclude.join("|"))
580+
exclude = @exclude
581+
exclude |= DEFAULT_EXCLUDE if @apply_default_exclude
582+
Regexp.new(exclude.join("|"))
571583
end
572584
end
573585

@@ -801,6 +813,11 @@ def parse argv
801813
@exclude << value
802814
end
803815

816+
opt.on("--[no-]apply-default-exclude",
817+
"Use default PATTERN to exclude.") do |value|
818+
@apply_default_exclude = value
819+
end
820+
804821
opt.separator nil
805822

806823
opt.on("--no-skipping-tests", nil,

test/rdoc/test_rdoc_options.rb

+25-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_to_yaml
6666
'charset' => 'UTF-8',
6767
'encoding' => encoding,
6868
'embed_mixins' => false,
69-
'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z],
69+
'exclude' => [],
7070
'hyperlink_all' => false,
7171
'line_numbers' => false,
7272
'locale_dir' => 'locale',
@@ -85,6 +85,7 @@ def test_to_yaml
8585
'warn_missing_rdoc_ref' => false,
8686
'webcvs' => nil,
8787
'skip_tests' => true,
88+
'apply_default_exclude' => true,
8889
}
8990

9091
assert_equal expected, coder
@@ -939,6 +940,29 @@ def test_no_skip_test_value
939940
assert_equal false, @options.skip_tests
940941
end
941942

943+
def test_apply_default_exclude_option
944+
@options.parse %w[]
945+
exclude = @options.exclude
946+
assert_kind_of Regexp, exclude
947+
assert_match exclude, "foo~"
948+
assert_match exclude, "foo.orig"
949+
assert_match exclude, "foo.rej"
950+
assert_match exclude, "foo.bak"
951+
assert_match exclude, "foo.gemspec"
952+
end
953+
954+
def test_no_apply_default_exclude_option
955+
@options.parse %w[--no-apply-default-exclude]
956+
assert_nil @options.exclude
957+
end
958+
959+
def test_exclude_option_without_default
960+
@options.parse %w[--no-apply-default-exclude --exclude=\.old\z]
961+
exclude = @options.exclude
962+
assert_match exclude, "foo.old"
963+
assert_not_match exclude, "foo~"
964+
end
965+
942966
class DummyCoder < Hash
943967
alias add :[]=
944968
def tag=(tag)

0 commit comments

Comments
 (0)