class StateFile

TODO: if you give it a nil filename, read gives you 0,0, write is a noop?

Public Class Methods

new(filename) click to toggle source
# File lib/redis_slowlog_stasher/statefile.rb, line 3
def initialize(filename)
  @filename = filename
end

Public Instance Methods

read() click to toggle source
# 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) click to toggle source
# File lib/redis_slowlog_stasher/statefile.rb, line 16
def write(entry_timestamp, entry_id)
  File.open(@filename, 'w') do |state_file|
    state_file.puts("#{entry_timestamp}:#{entry_id}")
  end
end