Skip to content

Commit

Permalink
Merge pull request #313 from elgalu/option_exclude_pattern
Browse files Browse the repository at this point in the history
New feature: Add directory() config[:exclude_pattern]
  • Loading branch information
sferik committed Mar 5, 2013
2 parents 1d92716 + a38446e commit 28201b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/thor/actions/directory.rb
Expand Up @@ -39,6 +39,7 @@ module Actions
# config<Hash>:: 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
#
Expand Down Expand Up @@ -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!('/./', '/')

Expand Down
13 changes: 13 additions & 0 deletions spec/actions/directory_spec.rb
Expand Up @@ -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! "."
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/doc/excluding/%file_name%.rb.tt
@@ -0,0 +1 @@
BAR = <%= "BAR" %>

0 comments on commit 28201b7

Please sign in to comment.