Class: Kameleoon::Events::EventManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/events/event_manager.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

EventManager stores SDK event handlers and fires SDK events.

Constant Summary collapse

HANDLER_METHODS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  EventType::HTTP_REQUEST => %i[on_request_succeeded on_request_failed],
  EventType::DATAFILE_UPDATE => %i[on_update]
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeEventManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EventManager.



21
22
23
# File 'lib/kameleoon/events/event_manager.rb', line 21

def initialize
  @event_handlers = {}
end

Instance Method Details

#fire_data_file_update(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
71
72
73
74
75
76
# File 'lib/kameleoon/events/event_manager.rb', line 67

def fire_data_file_update(event)
  handler = @event_handlers[EventType::DATAFILE_UPDATE]
  return if handler.nil?

  begin
    handler.on_update(event)
  rescue StandardError => e
    Logging::KameleoonLogger.warning('Data file update event handler failed: %s', e)
  end
end

#fire_http_request_failed(request_type, failure, duration_millis) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
65
# File 'lib/kameleoon/events/event_manager.rb', line 56

def fire_http_request_failed(request_type, failure, duration_millis)
  handler = @event_handlers[EventType::HTTP_REQUEST]
  return if handler.nil?

  begin
    handler.on_request_failed(request_type, failure, duration_millis)
  rescue StandardError => e
    Logging::KameleoonLogger.warning('HTTP request event handler failed: %s', e)
  end
end

#fire_http_request_succeeded(request_type, http_status, duration_millis) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
48
49
50
51
52
53
54
# File 'lib/kameleoon/events/event_manager.rb', line 45

def fire_http_request_succeeded(request_type, http_status, duration_millis)
  handler = @event_handlers[EventType::HTTP_REQUEST]
  return if handler.nil?

  begin
    handler.on_request_succeeded(request_type, http_status, duration_millis)
  rescue StandardError => e
    Logging::KameleoonLogger.warning('HTTP request event handler failed: %s', e)
  end
end

#set_event_handler(event_type, handler) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kameleoon/events/event_manager.rb', line 25

def set_event_handler(event_type, handler)
  handler_methods = HANDLER_METHODS[event_type]
  if handler_methods.nil?
    Logging::KameleoonLogger.error("Unknown event type '%s'", event_type)
    return
  end
  unless handler.nil? || handler_methods.all? { |method| handler.respond_to?(method) }
    Logging::KameleoonLogger.error(
      "Handler for event type '%s' must respond to the following methods: %s",
      event_type, handler_methods.join(', ')
    )
    return
  end
  if handler.nil?
    @event_handlers.delete(event_type)
  else
    @event_handlers[event_type] = handler
  end
end