Class: LogStash::Inputs::S3::SinceDB::File

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/inputs/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ File

Returns a new instance of File.



348
349
350
# File 'lib/logstash/inputs/s3.rb', line 348

def initialize(file)
  @sincedb_path = file
end

Instance Method Details

#newer?(date) ⇒ Boolean

Returns:

  • (Boolean)


352
353
354
# File 'lib/logstash/inputs/s3.rb', line 352

def newer?(date)
  date > read
end

#readObject



356
357
358
359
360
361
362
363
364
# File 'lib/logstash/inputs/s3.rb', line 356

def read
  if ::File.exists?(@sincedb_path)
    content = ::File.read(@sincedb_path).chomp.strip
    # If the file was created but we didn't have the time to write to it
    return content.empty? ? Time.new(0) : Time.parse(content)
  else
    return Time.new(0)
  end
end

#write(since = nil) ⇒ Object



366
367
368
369
# File 'lib/logstash/inputs/s3.rb', line 366

def write(since = nil)
  since = Time.now() if since.nil?
  ::File.open(@sincedb_path, 'w') { |file| file.write(since.to_s) }
end