Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Yield the filename on directories.

  • Loading branch information...
commit 3c4689447746277a14653fd8ae33e181deef4e45 1 parent 80d902e
@josevalim josevalim authored
View
7 CHANGELOG.rdoc
@@ -2,7 +2,12 @@
* Improve spec coverage for Thor::Runner
-== 0.11.x, released 2009-07-01
+== 0.12, released 2009-11-06
+
+* [#7] Do not force white color on status
+* [#8] Yield a block with the filename on directory
+
+== 0.11, released 2009-07-01
* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
Thor classes.
View
1  lib/thor/actions/create_file.rb
@@ -60,6 +60,7 @@ def invoke!
FileUtils.mkdir_p(File.dirname(destination))
File.open(destination, 'w'){ |f| f.write render }
end
+ given_destination
end
protected
View
14 lib/thor/actions/directory.rb
@@ -40,15 +40,16 @@ module Actions
# directory "doc"
# directory "doc", "docs", :recursive => false
#
- def directory(source, destination=nil, config={})
- action Directory.new(self, source, destination || source, config)
+ def directory(source, destination=nil, config={}, &block)
+ action Directory.new(self, source, destination || source, config, &block)
end
class Directory < EmptyDirectory #:nodoc:
attr_reader :source
- def initialize(base, source, destination=nil, config={})
+ def initialize(base, source, destination=nil, config={}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s))
+ @block = block
super(base, destination, { :recursive => true }.merge(config))
end
@@ -70,6 +71,7 @@ def execute!
Dir[lookup].each do |file_source|
next if File.directory?(file_source)
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
+ file_destination.gsub!('/./', '/')
case file_source
when /\.empty_directory$/
@@ -77,9 +79,11 @@ def execute!
next if dirname == given_destination
base.empty_directory(dirname, config)
when /\.tt$/
- base.template(file_source, file_destination[0..-4], config)
+ destination = base.template(file_source, file_destination[0..-4], config)
+ @block.call(destination) if @block
else
- base.copy_file(file_source, file_destination, config)
+ destination = base.copy_file(file_source, file_destination, config)
+ @block.call(destination) if @block
end
end
end
View
1  lib/thor/actions/empty_directory.rb
@@ -55,6 +55,7 @@ def invoke!
def revoke!
say_status :remove, :red
::FileUtils.rm_rf(destination) if !pretend? && exists?
+ given_destination
end
protected
View
4 spec/actions/create_file_spec.rb
@@ -50,9 +50,9 @@ def silence!
invoke!.must be_empty
end
- it "returns the destination" do
+ it "returns the given destination" do
capture(:stdout) do
- create_file("doc/config.rb").invoke!.must == File.join(destination_root, "doc/config.rb")
+ create_file("doc/config.rb").invoke!.must == "doc/config.rb"
end
end
View
7 spec/actions/directory_spec.rb
@@ -108,6 +108,13 @@ def exists_and_identical?(source_path, destination_path)
content.must =~ /create doc\/rdoc\.rb/
content.must =~ /create doc\/components/
end
+
+ it "yields a block" do
+ invoke!("doc") do |f|
+ %(doc/README doc/config.rb doc/rdoc.rb).must include(f)
+ %(doc/components/).must_not include(f)
+ end
+ end
end
describe "#revoke!" do
Please sign in to comment.
Something went wrong with that request. Please try again.