Skip to content

Commit

Permalink
can disable relativation of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
niklas committed May 15, 2011
1 parent 2f0870a commit a3cf121
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/guard/listener.rb
Expand Up @@ -26,6 +26,7 @@ def self.select_and_init
def initialize(directory=Dir.pwd)
@directory = directory.to_s
@sha1_checksums_hash = {}
@relativate_paths = true
update_last_event
end

Expand Down Expand Up @@ -64,11 +65,17 @@ def all_files

# 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

Expand Down
16 changes: 12 additions & 4 deletions spec/guard/listener_spec.rb
Expand Up @@ -38,10 +38,18 @@
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

Expand Down

0 comments on commit a3cf121

Please sign in to comment.