can specify directory to listen to, still defaulting to pwd
This commit is contained in:
parent
6a0121bcb9
commit
9c44f89a61
@ -8,7 +8,7 @@ module Guard
|
|||||||
autoload :Polling, 'guard/listeners/polling'
|
autoload :Polling, 'guard/listeners/polling'
|
||||||
|
|
||||||
class Listener
|
class Listener
|
||||||
attr_reader :last_event, :sha1_checksums_hash
|
attr_reader :last_event, :sha1_checksums_hash, :directory
|
||||||
|
|
||||||
def self.select_and_init
|
def self.select_and_init
|
||||||
if mac? && Darwin.usable?
|
if mac? && Darwin.usable?
|
||||||
@ -23,7 +23,8 @@ module Guard
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize(directory=Dir.pwd)
|
||||||
|
@directory = directory
|
||||||
@sha1_checksums_hash = {}
|
@sha1_checksums_hash = {}
|
||||||
update_last_event
|
update_last_event
|
||||||
end
|
end
|
||||||
@ -34,7 +35,7 @@ module Guard
|
|||||||
|
|
||||||
def modified_files(dirs, options = {})
|
def modified_files(dirs, options = {})
|
||||||
files = potentially_modified_files(dirs, options).select { |path| File.file?(path) && file_modified?(path) && file_content_modified?(path) }
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -8,7 +8,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_change(&callback)
|
def on_change(&callback)
|
||||||
@fsevent.watch Dir.pwd do |modified_dirs|
|
@fsevent.watch directory do |modified_dirs|
|
||||||
files = modified_files(modified_dirs)
|
files = modified_files(modified_dirs)
|
||||||
update_last_event
|
update_last_event
|
||||||
callback.call(files)
|
callback.call(files)
|
||||||
|
@ -22,7 +22,7 @@ module Guard
|
|||||||
|
|
||||||
def on_change(&callback)
|
def on_change(&callback)
|
||||||
@callback = 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
|
unless event.name == "" # Event on root directory
|
||||||
@files << event.absolute_name
|
@files << event.absolute_name
|
||||||
end
|
end
|
||||||
@ -61,7 +61,7 @@ module Guard
|
|||||||
|
|
||||||
unless files.empty?
|
unless files.empty?
|
||||||
files.uniq!
|
files.uniq!
|
||||||
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
|
files.map! { |file| file.gsub("#{directory}/", '') }
|
||||||
callback.call(files)
|
callback.call(files)
|
||||||
files.clear
|
files.clear
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ module Guard
|
|||||||
def watch_change
|
def watch_change
|
||||||
until @stop
|
until @stop
|
||||||
start = Time.now.to_f
|
start = Time.now.to_f
|
||||||
files = modified_files([Dir.pwd + '/'], :all => true)
|
files = modified_files([directory + '/'], :all => true)
|
||||||
update_last_event
|
update_last_event
|
||||||
callback.call(files) unless files.empty?
|
callback.call(files) unless files.empty?
|
||||||
nap_time = latency - (Time.now.to_f - start)
|
nap_time = latency - (Time.now.to_f - start)
|
||||||
|
@ -8,7 +8,7 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_change(&callback)
|
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) + '/']
|
paths = [File.expand_path(event.watcher.path) + '/']
|
||||||
files = modified_files(paths, {:all => true})
|
files = modified_files(paths, {:all => true})
|
||||||
update_last_event
|
update_last_event
|
||||||
|
Loading…
Reference in New Issue
Block a user