Class: FileHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileHandler

Returns a new instance of FileHandler.



51
52
53
54
# File 'lib/logstash/inputs/value_tracking.rb', line 51

def initialize(path)
  @path = path
  @exists = ::File.exist?(@path)
end

Instance Method Details

#cleanObject



56
57
58
59
60
# File 'lib/logstash/inputs/value_tracking.rb', line 56

def clean
  return unless @exists
  ::File.delete(@path)
  @exists = false
end

#readObject



62
63
64
65
# File 'lib/logstash/inputs/value_tracking.rb', line 62

def read
  return unless @exists
  YAML.load(::File.read(@path))
end

#write(value) ⇒ Object



67
68
69
70
# File 'lib/logstash/inputs/value_tracking.rb', line 67

def write(value)
  ::File.write(@path, YAML.dump(value))
  @exists = true
end