Class: Servolux::Daemon::LogfileReader
- Inherits:
-
Object
- Object
- Servolux::Daemon::LogfileReader
- Defined in:
- lib/servolux/daemon.rb
Overview
:stopdoc:
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#look_for ⇒ Object
Returns the value of attribute look_for.
Instance Method Summary collapse
-
#initialize ⇒ LogfileReader
constructor
A new instance of LogfileReader.
- #stat ⇒ Object
- #updated? ⇒ Boolean
Constructor Details
#initialize ⇒ LogfileReader
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
#filename ⇒ Object
Returns the value of attribute filename.
417 418 419 |
# File 'lib/servolux/daemon.rb', line 417 def filename @filename end |
#look_for ⇒ Object
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
#stat ⇒ Object
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
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 |