can specify directory to listen to, still defaulting to pwd

This commit is contained in:
Niklas Hofer 2011-05-13 20:54:39 +02:00
parent 6a0121bcb9
commit 9c44f89a61
5 changed files with 9 additions and 8 deletions

View File

@ -8,7 +8,7 @@ module Guard
autoload :Polling, 'guard/listeners/polling'
class Listener
attr_reader :last_event, :sha1_checksums_hash
attr_reader :last_event, :sha1_checksums_hash, :directory
def self.select_and_init
if mac? && Darwin.usable?
@ -23,7 +23,8 @@ module Guard
end
end
def initialize
def initialize(directory=Dir.pwd)
@directory = directory
@sha1_checksums_hash = {}
update_last_event
end
@ -34,7 +35,7 @@ module Guard
def modified_files(dirs, options = {})
files = potentially_modified_files(dirs, options).select { |path| File.file?(path) && file_modified?(path) && file_content_modified?(path) }
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
files.map! { |file| file.gsub("#{directory}/", '') }
end
private

View File

@ -8,7 +8,7 @@ module Guard
end
def on_change(&callback)
@fsevent.watch Dir.pwd do |modified_dirs|
@fsevent.watch directory do |modified_dirs|
files = modified_files(modified_dirs)
update_last_event
callback.call(files)

View File

@ -22,7 +22,7 @@ module Guard
def on_change(&callback)
@callback = callback
inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
inotify.watch(directory, :recursive, :modify, :create, :delete, :move) do |event|
unless event.name == "" # Event on root directory
@files << event.absolute_name
end
@ -61,7 +61,7 @@ module Guard
unless files.empty?
files.uniq!
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
files.map! { |file| file.gsub("#{directory}/", '') }
callback.call(files)
files.clear
end

View File

@ -25,7 +25,7 @@ module Guard
def watch_change
until @stop
start = Time.now.to_f
files = modified_files([Dir.pwd + '/'], :all => true)
files = modified_files([directory + '/'], :all => true)
update_last_event
callback.call(files) unless files.empty?
nap_time = latency - (Time.now.to_f - start)

View File

@ -8,7 +8,7 @@ module Guard
end
def on_change(&callback)
@fchange.watch(Dir.pwd, :all_events, :recursive) do |event|
@fchange.watch(directory, :all_events, :recursive) do |event|
paths = [File.expand_path(event.watcher.path) + '/']
files = modified_files(paths, {:all => true})
update_last_event