File: tailer.rb

package info (click to toggle)
ruby-file-tail 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 188 kB
  • sloc: ruby: 887; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class File
  module Tail
    # This class supervises activity on a tailed fail and collects newly read
    # lines until the Tail::Group fetches and processes them.
    class Tailer < ::Thread

      # True if there are any lines pending on this Tailer, false otherwise.
      def pending_lines?
        !queue.empty?
      end

      # Fetch all the pending lines from this Tailer and thereby remove them
      # from the Tailer's queue.
      def pending_lines
        Array.new(queue.size) { queue.deq(true) }
      end

      alias stop exit # Stop tailing this file and remove it from its File::Tail::Group.

      # Return true if the thread local variable +id+ is defined or if this
      # object responds to the method +id+.
      def respond_to?(id)
        !self[id].nil? || super
      end

      # Return the thread local variable +id+ if it is defined.
      def method_missing(id, *args, &block)
        if args.empty? && !(value = self[id]).nil?
          value
        else
          super
        end
      end
    end
  end
end