Class: LogStash::Inputs::GoogleCloudStorage::SinceDB::File
- Inherits:
-
Object
- Object
- LogStash::Inputs::GoogleCloudStorage::SinceDB::File
- Defined in:
- lib/logstash/inputs/google_cloud_storage.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ File
constructor
A new instance of File.
- #newer?(date) ⇒ Boolean
- #read ⇒ Object
- #write(since = nil) ⇒ Object
Constructor Details
#initialize(file) ⇒ File
Returns a new instance of File.
398 399 400 |
# File 'lib/logstash/inputs/google_cloud_storage.rb', line 398 def initialize(file) @sincedb_path = file end |
Instance Method Details
#newer?(date) ⇒ Boolean
402 403 404 |
# File 'lib/logstash/inputs/google_cloud_storage.rb', line 402 def newer?(date) date.to_i > read.to_i end |
#read ⇒ Object
406 407 408 409 410 411 412 413 414 |
# File 'lib/logstash/inputs/google_cloud_storage.rb', line 406 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
416 417 418 419 |
# File 'lib/logstash/inputs/google_cloud_storage.rb', line 416 def write(since = nil) since = Time.now() if since.nil? ::File.open(@sincedb_path, 'w') { |file| file.write(since.to_s) } end |