Class: Optimizely::NotificationCenterRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/notification_center_registry.rb

Class Method Summary collapse

Class Method Details

.get_notification_center(sdk_key, logger) ⇒ Object

Returns: nil or NotificationCenter



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/optimizely/notification_center_registry.rb', line 38

def self.get_notification_center(sdk_key, logger)
  unless sdk_key
    logger&.log(Logger::ERROR, "#{MissingSdkKeyError.new.message} ODP may not work properly without it.")
    return nil
  end

  notification_center = nil

  @mutex.synchronize do
    if @notification_centers.key?(sdk_key)
      notification_center = @notification_centers[sdk_key]
    else
      notification_center = NotificationCenter.new(logger, nil)
      @notification_centers[sdk_key] = notification_center
    end
  end

  notification_center
end

.remove_notification_center(sdk_key) ⇒ Object

Args: sdk_key: The sdk_key of the notification center to remove.



62
63
64
65
66
67
68
69
# File 'lib/optimizely/notification_center_registry.rb', line 62

def self.remove_notification_center(sdk_key)
  @mutex.synchronize do
    @notification_centers
      .delete(sdk_key)
      &.clear_all_notification_listeners
  end
  nil
end