Class: Threatstack::Events::EventAccumulator
- Inherits:
-
Object
- Object
- Threatstack::Events::EventAccumulator
- Includes:
- Singleton
- Defined in:
- lib/events/event_accumulator.rb
Overview
Singleton class that handles temporarily caching events until they’re sent to the back end
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #clear_events ⇒ Object
-
#initialize ⇒ EventAccumulator
constructor
A new instance of EventAccumulator.
- #remove_events(num = 1) ⇒ Object
Constructor Details
#initialize ⇒ EventAccumulator
Returns a new instance of EventAccumulator.
15 16 17 18 |
# File 'lib/events/event_accumulator.rb', line 15 def initialize @events = [] @logger = Threatstack::Utils::TSLogger.create 'EventAccumulator' end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
13 14 15 |
# File 'lib/events/event_accumulator.rb', line 13 def events @events end |
Instance Method Details
#add_event(event) ⇒ Object
20 21 22 23 |
# File 'lib/events/event_accumulator.rb', line 20 def add_event(event) @logger.debug "Adding event - New Total: #{@events.length + 1}" @events.push(event) end |
#clear_events ⇒ Object
30 31 32 33 |
# File 'lib/events/event_accumulator.rb', line 30 def clear_events @logger.debug "Clearing events - Total: #{@events.length}" @events.clear end |
#remove_events(num = 1) ⇒ Object
25 26 27 28 |
# File 'lib/events/event_accumulator.rb', line 25 def remove_events(num = 1) @logger.debug "Removing #{num} event(s) - New Total: #{@events.length - num}" @events.shift(num) end |