Class: LogTail::FileStateStore
- Inherits:
-
Object
- Object
- LogTail::FileStateStore
- Defined in:
- lib/apache_log_tail.rb
Overview
This is the default implementation of StateStore, which stores the state in a file ( by default in /tmp with a static name although this is configurable).
Instance Attribute Summary collapse
-
#path_to_file ⇒ Object
Provides the path to the file that is used to store the state ( unless a custom StateStore is used).
Instance Method Summary collapse
-
#recall ⇒ Hash
Retrieves the state from the store.
-
#remember(state) ⇒ Object
Stores the supplied state.
Instance Attribute Details
#path_to_file ⇒ Object
Provides the path to the file that is used to store the state ( unless a custom StateStore is used).
70 71 72 |
# File 'lib/apache_log_tail.rb', line 70 def path_to_file @path_to_file ||= "/tmp/.apache_log_tail-state.yml" end |
Instance Method Details
#recall ⇒ Hash
Retrieves the state from the store.
80 81 82 83 84 85 86 |
# File 'lib/apache_log_tail.rb', line 80 def recall if not File.exists? path_to_file {} else YAML.load File.read( path_to_file) end end |
#remember(state) ⇒ Object
Stores the supplied state.
91 92 93 94 95 |
# File 'lib/apache_log_tail.rb', line 91 def remember state File.open path_to_file, "w" do |file| file.write state.to_yaml end end |