Class: EventMachine::FileGlobWatchTail
- Inherits:
-
FileGlobWatch
- Object
- FileGlobWatch
- EventMachine::FileGlobWatchTail
- Defined in:
- lib/em/globwatcher.rb
Overview
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
Instance Method Summary collapse
- #file_deleted(path) ⇒ Object
- #file_error(path, e) ⇒ Object
- #file_excluded(path) ⇒ Object
- #file_found(path) ⇒ Object
-
#initialize(path, handler = nil, interval = 60, exclude = [], *args, &block) ⇒ FileGlobWatchTail
constructor
A new instance of FileGlobWatchTail.
Methods inherited from FileGlobWatch
Constructor Details
#initialize(path, handler = nil, interval = 60, exclude = [], *args, &block) ⇒ FileGlobWatchTail
Returns a new instance of FileGlobWatchTail.
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/em/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 |
Instance Method Details
#file_deleted(path) ⇒ Object
240 241 242 |
# File 'lib/em/globwatcher.rb', line 240 def file_deleted(path) # Nothing to do end |
#file_error(path, e) ⇒ Object
245 246 247 248 |
# File 'lib/em/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) ⇒ Object
235 236 237 |
# File 'lib/em/globwatcher.rb', line 235 def file_excluded(path) @logger.info "#{self.class}: Skipping path #{path} due to exclude rule" end |
#file_found(path) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/em/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 |