class Phoenix::Inbox
Attributes
data[R]
ttl[R]
Public Class Methods
new(ttl:)
click to toggle source
Calls superclass method
# File lib/yatapp/inbox.rb, line 8 def initialize(ttl:) @ttl = ttl @bucket = Time.now.to_i / ttl @data = Hash.new { |h, k| h[k] = {} } super() end
Public Instance Methods
current_timestamp()
click to toggle source
# File lib/yatapp/inbox.rb, line 41 def current_timestamp Time.now.to_i / ttl end
key?(key)
click to toggle source
# File lib/yatapp/inbox.rb, line 37 def key?(key) data.values.any? { |v| v.key?(key) } end
pop(key) { || ... }
click to toggle source
# File lib/yatapp/inbox.rb, line 28 def pop(key) synchronize do ts = current_timestamp data[ts - 1].delete(key) { data[ts].delete(key) { yield }} end end
Also aliased as: delete
push(key, val)
click to toggle source
# File lib/yatapp/inbox.rb, line 15 def push(key, val) synchronize do ts = current_timestamp (data[ts][key] = val).tap do if data.keys.size >= 3 data.delete_if { |key, _| key < (ts - 1) } end end end end
Also aliased as: []=