trabajo-afectivo/lib/event_buffer.rb

30 lines
696 B
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
2013-06-19 12:04:09 +00:00
module EventBuffer
2016-04-13 23:50:22 +00:00
def self.list(key)
if !Thread.current[:event_buffer]
Thread.current[:event_buffer] = {}
end
Thread.current[:event_buffer][key] || []
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
def self.add(key, item)
2013-06-19 12:04:09 +00:00
if !Thread.current[:event_buffer]
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer] = {}
end
if !Thread.current[:event_buffer][key]
Thread.current[:event_buffer][key] = []
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer][key].push item
2013-06-19 12:04:09 +00:00
end
2016-04-13 23:50:22 +00:00
def self.reset(key)
return if !Thread.current[:event_buffer]
return if !Thread.current[:event_buffer][key]
2016-04-13 23:50:22 +00:00
Thread.current[:event_buffer][key] = []
2013-06-19 12:04:09 +00:00
end
end