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

Returns a new instance of LogfileReader


420
421
422
423
# File 'lib/servolux/daemon.rb', line 420

def initialize
  @filename = nil
  @look_for = nil
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename


417
418
419
# File 'lib/servolux/daemon.rb', line 417

def filename
  @filename
end

#look_forObject

Returns the value of attribute look_for


418
419
420
# File 'lib/servolux/daemon.rb', line 418

def look_for
  @look_for
end

Instance Method Details

#statObject


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

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

#updated?Boolean

Returns:

  • (Boolean)

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/servolux/daemon.rb', line 441

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