Class: Fluent::FeedlyInput::StateStore
- Inherits:
-
Object
- Object
- Fluent::FeedlyInput::StateStore
- Defined in:
- lib/fluent/plugin/in_feedly.rb
Overview
implementation has copied from its code. github.com/fluent/fluent-plugin-sql/blob/master/lib/fluent/plugin/in_sql.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(path) ⇒ StateStore
constructor
A new instance of StateStore.
- #set(key, data) ⇒ Object
- #update! ⇒ Object
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 |