Class: Threatstack::Events::EventAccumulator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeEventAccumulator

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

#eventsObject (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_eventsObject



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