Class: EventMachine::FileGlobWatchTail

Inherits:
FileGlobWatch show all
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

Methods inherited from FileGlobWatch

#file_modified, #start, #stop

Constructor Details

#initialize(path, handler = nil, interval = 60, exclude = [], *args, &block) ⇒ FileGlobWatchTail

Returns a new instance of FileGlobWatchTail.



215
216
217
218
219
220
221
222
223
224
# File 'lib/em/globwatcher.rb', line 215

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



257
258
259
# File 'lib/em/globwatcher.rb', line 257

def file_deleted(path)
  # Nothing to do
end

#file_error(path, e) ⇒ Object



262
263
264
265
# File 'lib/em/globwatcher.rb', line 262

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



252
253
254
# File 'lib/em/globwatcher.rb', line 252

def file_excluded(path)
  @logger.info "#{self.class}: Skipping path #{path} due to exclude rule"
end

#file_found(path) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/em/globwatcher.rb', line 227

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