diff --git a/lib/thor/actions/directory.rb b/lib/thor/actions/directory.rb index 1505461cb..7f8fd97c9 100644 --- a/lib/thor/actions/directory.rb +++ b/lib/thor/actions/directory.rb @@ -39,6 +39,7 @@ module Actions # config:: give :verbose => false to not log the status. # If :recursive => false, does not look for paths recursively. # If :mode => :preserve, preserve the file mode from the source. + # If :exclude_pattern => /regexp/, prevents copying files that match that regexp. # # ==== Examples # @@ -78,6 +79,7 @@ def execute! files(lookup).sort.each do |file_source| next if File.directory?(file_source) + next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern]) file_destination = File.join(given_destination, file_source.gsub(source, '.')) file_destination.gsub!('/./', '/') diff --git a/spec/actions/directory_spec.rb b/spec/actions/directory_spec.rb index 46323b24e..b7e70f2c5 100644 --- a/spec/actions/directory_spec.rb +++ b/spec/actions/directory_spec.rb @@ -68,6 +68,19 @@ def exists_and_identical?(source_path, destination_path) expect(File.exists?(file)).to be_false end + it "ignores files within excluding/ directories when exclude_pattern is provided" do + invoke! "doc", "docs", :exclude_pattern => /excluding\// + file = File.join(destination_root, "docs", "excluding", "rdoc.rb") + expect(File.exists?(file)).to be_false + end + + it "copies and evalutes files within excluding/ directory when no exclude_pattern is present" do + invoke! "doc", "docs" + file = File.join(destination_root, "docs", "excluding", "rdoc.rb") + expect(File.exists?(file)).to be_true + expect(File.read(file)).to eq("BAR = BAR\n") + end + it "copies files from the source relative to the current path" do invoker.inside "doc" do invoke! "." diff --git a/spec/fixtures/doc/excluding/%file_name%.rb.tt b/spec/fixtures/doc/excluding/%file_name%.rb.tt new file mode 100644 index 000000000..6296c46ed --- /dev/null +++ b/spec/fixtures/doc/excluding/%file_name%.rb.tt @@ -0,0 +1 @@ +BAR = <%= "BAR" %>