Class: Fluent::SpectrumInput::StateStore
- Inherits:
-
Object
- Object
- Fluent::SpectrumInput::StateStore
- Defined in:
- lib/fluent/plugin/in_spectrum.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ StateStore
constructor
A new instance of StateStore.
- #last_records ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(path) ⇒ StateStore
Returns a new instance of StateStore.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fluent/plugin/in_spectrum.rb', line 34 def initialize(path) require 'yaml' @path = path if File.exists?(@path) @data = YAML.load_file(@path) if @data == false || @data == [] # this happens if an users created an empty file accidentally @data = {} elsif !@data.is_a?(Hash) raise "state_file on #{@path.inspect} is invalid" end else @data = {} end end |
Instance Method Details
#last_records ⇒ Object
50 51 52 |
# File 'lib/fluent/plugin/in_spectrum.rb', line 50 def last_records @data['last_records'] ||= {} end |
#update! ⇒ Object
54 55 56 57 58 |
# File 'lib/fluent/plugin/in_spectrum.rb', line 54 def update! File.open(@path, 'w') {|f| f.write YAML.dump(@data) } end |