Skip to content

Commit

Permalink
Separate patterns by --exclude option from defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 24, 2024
1 parent 8a367a9 commit e10554b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
31 changes: 24 additions & 7 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,24 @@ class RDoc::Options
# +--[no-]embed-mixins+ (Default is +false+.)
attr_accessor :embed_mixins

##
# Exclude the default patterns as well if true.
attr_reader :apply_default_exclude

def initialize loaded_options = nil # :nodoc:
init_ivars
override loaded_options if loaded_options
end

DEFAULT_EXCLUDE = %w[
~\z \.orig\z \.rej\z \.bak\z
\.gemspec\z
]

def init_ivars # :nodoc:
@dry_run = false
@embed_mixins = false
@exclude = %w[
~\z \.orig\z \.rej\z \.bak\z
\.gemspec\z
]
@exclude = []
@files = nil
@force_output = false
@force_update = true
Expand Down Expand Up @@ -405,6 +411,7 @@ def init_ivars # :nodoc:
@encoding = Encoding::UTF_8
@charset = @encoding.name
@skip_tests = true
@apply_default_exclude = true
end

def init_with map # :nodoc:
Expand All @@ -430,6 +437,7 @@ def init_with map # :nodoc:
@title = map['title']
@visibility = map['visibility']
@webcvs = map['webcvs']
@apply_default_exclude = map['apply_default_exclude']

@rdoc_include = sanitize_path map['rdoc_include']
@static_path = sanitize_path map['static_path']
Expand Down Expand Up @@ -463,6 +471,7 @@ def override map # :nodoc:
@title = map['title'] if map.has_key?('title')
@visibility = map['visibility'] if map.has_key?('visibility')
@webcvs = map['webcvs'] if map.has_key?('webcvs')
@apply_default_exclude = map['apply_default_exclude'] if map.has_key?('apply_default_exclude')

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

Expand Down Expand Up @@ -493,7 +502,8 @@ def == other # :nodoc:
@template == other.template and
@title == other.title and
@visibility == other.visibility and
@webcvs == other.webcvs
@webcvs == other.webcvs and
@apply_default_exclude == other.apply_default_exclude
end

##
Expand Down Expand Up @@ -564,10 +574,12 @@ def exclude
if @exclude.nil? or Regexp === @exclude then
# done, #finish is being re-run
@exclude
elsif @exclude.empty? then
elsif !@apply_default_exclude and @exclude.empty? then
nil
else
Regexp.new(@exclude.join("|"))
exclude = @exclude
exclude |= DEFAULT_EXCLUDE if @apply_default_exclude
Regexp.new(exclude.join("|"))
end
end

Expand Down Expand Up @@ -801,6 +813,11 @@ def parse argv
@exclude << value
end

opt.on("--[no-]apply-default-exclude",
"Use default PATTERN to exclude.") do |value|
@apply_default_exclude = value
end

opt.separator nil

opt.on("--no-skipping-tests", nil,
Expand Down
26 changes: 25 additions & 1 deletion test/rdoc/test_rdoc_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_to_yaml
'charset' => 'UTF-8',
'encoding' => encoding,
'embed_mixins' => false,
'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z],
'exclude' => [],
'hyperlink_all' => false,
'line_numbers' => false,
'locale_dir' => 'locale',
Expand All @@ -85,6 +85,7 @@ def test_to_yaml
'warn_missing_rdoc_ref' => false,
'webcvs' => nil,
'skip_tests' => true,
'apply_default_exclude' => true,
}

assert_equal expected, coder
Expand Down Expand Up @@ -939,6 +940,29 @@ def test_no_skip_test_value
assert_equal false, @options.skip_tests
end

def test_apply_default_exclude_option
@options.parse %w[]
exclude = @options.exclude
assert_kind_of Regexp, exclude
assert_match exclude, "foo~"
assert_match exclude, "foo.orig"
assert_match exclude, "foo.rej"
assert_match exclude, "foo.bak"
assert_match exclude, "foo.gemspec"
end

def test_no_apply_default_exclude_option
@options.parse %w[--no-apply-default-exclude]
assert_nil @options.exclude
end

def test_exclude_option_without_default
@options.parse %w[--no-apply-default-exclude --exclude=\.old\z]
exclude = @options.exclude
assert_match exclude, "foo.old"
assert_not_match exclude, "foo~"
end

class DummyCoder < Hash
alias add :[]=
def tag=(tag)
Expand Down

0 comments on commit e10554b

Please sign in to comment.