Class: LogStash::Inputs::GCS::SinceDB::File
- Inherits:
-
Object
- Object
- LogStash::Inputs::GCS::SinceDB::File
- Defined in:
- lib/logstash/inputs/gcs.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.
290 291 292 |
# File 'lib/logstash/inputs/gcs.rb', line 290 def initialize(file) @sincedb_path = file end |
Instance Method Details
#newer?(date) ⇒ Boolean
294 295 296 |
# File 'lib/logstash/inputs/gcs.rb', line 294 def newer?(date) date > read end |
#read ⇒ Object
298 299 300 301 302 303 304 305 306 |
# File 'lib/logstash/inputs/gcs.rb', line 298 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
308 309 310 311 |
# File 'lib/logstash/inputs/gcs.rb', line 308 def write(since = nil) since = Time.now() if since.nil? ::File.open(@sincedb_path, 'w') { |file| file.write(since.strftime("%Y-%m-%d %H:%M:%S.%L %Z")) } end |