class BBS::RateLimit::Memory
The events of a limit in memory, by monotonic time.
Public Class Methods
Source
# File lib/bbs/rate_limit.rb, line 103 def initialize @times = {} @pruned = now end
Creates an empty store.
Public Instance Methods
Source
# File lib/bbs/rate_limit.rb, line 121 def add(key, time) = (@times[key] ||= []) << time
Keeps an event of key at time.
Source
# File lib/bbs/rate_limit.rb, line 109 def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
The current time of this store: monotonic seconds.
Source
# File lib/bbs/rate_limit.rb, line 113 def since(key, start) prune(start) times = @times[key] or return [] times.shift while times.any? && times.first <= start times end
The times of key‘s events after start, oldest first; older ones are dropped.