Module: EventMachine
- Defined in:
- lib/em/globwatcher.rb,
lib/em/filetail.rb
Overview
Add EventMachine::file_tail
Defined Under Namespace
Classes: FileTail
Class Method Summary collapse
-
.file_tail(path, handler = nil, *args, &block) ⇒ Object
Tail a file.
-
.glob_tail(glob, handler = nil, *args, &block) ⇒ Object
Watch a glob and tail any files found.
-
.watch_glob(glob, handler = nil, *args) {|c| ... } ⇒ Object
Watch a glob for any files.
Class Method Details
.file_tail(path, handler = nil, *args, &block) ⇒ Object
Tail a file.
path is the path to the file to tail. handler should be a module implementing ‘receive_data’ or must be a subclasses of EventMachine::FileTail
For example:
EM::file_tail("/var/log/messages", MyHandler)
If a block is given, and the handler is not specified or does not implement EventMachine::FileTail#receive_data, then it will be called as such:
EM::file_tail(...) do |filetail, line|
# filetail is the FileTail instance watching the file
# line is the line read from the file
end
463 464 465 466 467 468 469 470 |
# File 'lib/em/filetail.rb', line 463 def self.file_tail(path, handler=nil, *args, &block) # This code mostly styled on what EventMachine does in many of it's other # methods. args = [path, *args] klass = klass_from_handler(EventMachine::FileTail, handler, *args); c = klass.new(*args, &block) return c end |
.glob_tail(glob, handler = nil, *args, &block) ⇒ Object
Watch a glob and tail any files found.
-
glob - a string path or glob, such as /var/log/*.log
-
handler - a module or subclass of EventMachine::FileGlobWatchTail. handler can be omitted if you give a block.
If you give a block and omit the handler parameter, then the behavior is that your block is called for every line read from any file the same way EventMachine::file_tail does when called with a block.
See EventMachine::FileGlobWatchTail for the callback methods.
See EventMachine::file_tail for more information about block behavior.
264 265 266 267 268 269 270 |
# File 'lib/em/globwatcher.rb', line 264 def self.glob_tail(glob, handler=nil, *args, &block) handler = EventMachine::FileGlobWatchTail if handler == nil args.unshift(glob) klass = klass_from_handler(EventMachine::FileGlobWatchTail, handler, *args) c = klass.new(*args, &block) return c end |
.watch_glob(glob, handler = nil, *args) {|c| ... } ⇒ Object
Watch a glob for any files.
-
glob - a string path or glob, such as “/var/log/*.log”
-
handler - must be a module or a subclass of EventMachine::FileGlobWatch
The remaining (optional) arguments are passed to your handler like this:
If you call this:
EventMachine.watch_glob("/var/log/*.log", YourHandler, 1, 2, 3, ...)
This will be invoked when new matching files are found:
YourHandler.new(path_found, 1, 2, 3, ...)
^ path_found is the new path found by the glob
See EventMachine::FileGlobWatch for the callback methods.
285 286 287 288 289 290 291 292 293 |
# File 'lib/em/globwatcher.rb', line 285 def self.watch_glob(glob, handler=nil, *args) # This code mostly styled on what EventMachine does in many of it's other # methods. args = [glob, *args] klass = klass_from_handler(EventMachine::FileGlobWatch, handler, *args); c = klass.new(*args) yield c if block_given? return c end |