class EventMachine::FileGlobWatchTail
A glob tailer for EventMachine
This class combines features of EventMachine::file_tail
and EventMachine::watch_glob
.
You won't generally subclass this class (See EventMachine::FileGlobWatch
)
See also: EventMachine::glob_tail
Public Class Methods
new(path, handler=nil, interval=60, exclude=[], *args, &block)
click to toggle source
Initialize a new file glob tail.
-
path - glob or file path (string)
-
handler - a module or subclass of
EventMachine::FileTail
See alsoEventMachine::file_tail
-
interval - how often (seconds) the glob path should be scanned
-
exclude - an array of Regexp (or anything with .match) for excluding from things to tail
The remainder of arguments are passed to EventMachine::file_tail
as
EventMachine::file_tail(path_found, handler, *args, &block)
Calls superclass method
EventMachine::FileGlobWatch::new
# File lib/event_machine/tail/globwatcher.rb, line 198 def initialize(path, handler=nil, interval=60, exclude=[], *args, &block) super(path, interval) @handler = handler @args = args @exclude = exclude if block_given? @handler = block end end
Public Instance Methods
file_deleted(path)
click to toggle source
# File lib/event_machine/tail/globwatcher.rb, line 240 def file_deleted(path) # Nothing to do end
file_error(path, e)
click to toggle source
# File lib/event_machine/tail/globwatcher.rb, line 245 def file_error(path, e) $stderr.puts "#{e.class} while trying to tail #{path}" # otherwise, drop the error by default end
file_excluded(path)
click to toggle source
# File lib/event_machine/tail/globwatcher.rb, line 235 def file_excluded(path) @logger.info "#{self.class}: Skipping path #{path} due to exclude rule" end
file_found(path)
click to toggle source
# File lib/event_machine/tail/globwatcher.rb, line 210 def file_found(path) begin @logger.info "#{self.class}: Trying #{path}" @exclude.each do |exclude| @logger.info "#{self.class}: Testing #{exclude} =~ #{path} == #{exclude.match(path) != nil}" if exclude.match(path) != nil file_excluded(path) return end end @logger.info "#{self.class}: Watching #{path}" if @handler.is_a? Proc EventMachine::file_tail(path, nil, *@args, &@handler) else EventMachine::file_tail(path, @handler, *@args) end rescue Errno::EACCES => e file_error(path, e) rescue Errno::EISDIR => e file_error(path, e) end end