can disable relativation of paths

This commit is contained in:
Niklas Hofer 2011-05-15 19:00:15 +02:00
parent 2f0870abfc
commit a3cf121111
2 changed files with 19 additions and 4 deletions

View File

@ -26,6 +26,7 @@ module Guard
def initialize(directory=Dir.pwd)
@directory = directory.to_s
@sha1_checksums_hash = {}
@relativate_paths = true
update_last_event
end
@ -64,11 +65,17 @@ module Guard
# scopes all given paths to the current #directory
def relativate_paths(paths)
return paths unless relativate_paths?
paths.map do |path|
path.gsub(%r~^#{directory}/~, '')
end
end
attr_writer :relativate_paths
def relativate_paths?
!!@relativate_paths
end
private

View File

@ -38,10 +38,18 @@ describe Guard::Listener do
end
describe "#relativate_paths" do
subject { described_class.new }
it "should relavate paths to the configured directory" do
subject.stub!(:directory).and_return('/tmp')
subject.relativate_paths(%w( /tmp/a /tmp/a/b /tmp/a.b/c.d )).should =~ %w( a a/b a.b/c.d )
subject { described_class.new('/tmp') }
before :each do
@paths = %w( /tmp/a /tmp/a/b /tmp/a.b/c.d )
end
it "should relativate paths to the configured directory" do
subject.relativate_paths(@paths).should =~ %w( a a/b a.b/c.d )
end
it "can be disabled" do
subject.relativate_paths = false
subject.relativate_paths(@paths).should == @paths
end
end