Class: LogStash::PluginMixins::FileHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileHandler



93
94
95
96
# File 'lib/logstash/plugin_mixins/value_tracking.rb', line 93

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

Instance Method Details

#cleanObject



98
99
100
101
102
# File 'lib/logstash/plugin_mixins/value_tracking.rb', line 98

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

#readObject



104
105
106
107
# File 'lib/logstash/plugin_mixins/value_tracking.rb', line 104

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

#write(value) ⇒ Object



109
110
111
112
# File 'lib/logstash/plugin_mixins/value_tracking.rb', line 109

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