Class: Servolux::Daemon::LogfileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/servolux/daemon.rb

Overview

:stopdoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogfileReader


436
437
438
439
# File 'lib/servolux/daemon.rb', line 436

def initialize
  @filename = nil
  @look_for = nil
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename


433
434
435
# File 'lib/servolux/daemon.rb', line 433

def filename
  @filename
end

#look_forObject

Returns the value of attribute look_for


434
435
436
# File 'lib/servolux/daemon.rb', line 434

def look_for
  @look_for
end

Instance Method Details

#statObject


452
453
454
455
# File 'lib/servolux/daemon.rb', line 452

def stat
  s = File.stat(@filename) if @filename && test(?f, @filename)
  s || OpenStruct.new(:mtime => Time.at(0), :size => 0)
end

#updated?Boolean


457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/servolux/daemon.rb', line 457

def updated?
  s = stat
  @stat ||= s

  return false if s.nil?
  return false if @stat.mtime == s.mtime and @stat.size == s.size
  return true if @look_for.nil?

  File.open(@filename, 'r') do |fd|
    fd.seek @stat.size, IO::SEEK_SET
    while line = fd.gets
      return true if line =~ @look_for
    end
  end

  return false
ensure
  @stat = s
end