Class: StateFile
- Inherits:
-
Object
- Object
- StateFile
- Defined in:
- lib/redis_slowlog_stasher/statefile.rb
Overview
TODO: if you give it a nil filename, read gives you 0,0, write is a noop?
Instance Method Summary collapse
-
#initialize(filename) ⇒ StateFile
constructor
A new instance of StateFile.
- #read ⇒ Object
- #write(entry_timestamp, entry_id) ⇒ Object
Constructor Details
#initialize(filename) ⇒ StateFile
Returns a new instance of StateFile.
3 4 5 |
# File 'lib/redis_slowlog_stasher/statefile.rb', line 3 def initialize(filename) @filename = filename end |
Instance Method Details
#read ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/redis_slowlog_stasher/statefile.rb', line 7 def read File.open(@filename, 'r') do |state_file| state_file.gets.chomp.split(':').map(&:to_i) end rescue Errno::ENOENT # if the file doesn't exist, just return the thing [0,0] end |
#write(entry_timestamp, entry_id) ⇒ Object
16 17 18 19 20 |
# File 'lib/redis_slowlog_stasher/statefile.rb', line 16 def write(, entry_id) File.open(@filename, 'w') do |state_file| state_file.puts("#{}:#{entry_id}") end end |