Class: Fluent::FeedlyInput::StateStore

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_feedly.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ StateStore

Returns a new instance of StateStore.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/fluent/plugin/in_feedly.rb', line 118

def initialize(path)
  @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

#get(key) ⇒ Object



137
138
139
# File 'lib/fluent/plugin/in_feedly.rb', line 137

def get(key)
  @data[key.to_sym] ||= {}
end

#set(key, data) ⇒ Object



133
134
135
# File 'lib/fluent/plugin/in_feedly.rb', line 133

def set(key, data)
  @data.store(key.to_sym, data)
end

#update!Object



141
142
143
144
145
# File 'lib/fluent/plugin/in_feedly.rb', line 141

def update!
  File.open(@path, 'w') {|f|
    f.write YAML.dump(@data)
  }
end