Class: AdManagerApi::Utils::UtilityRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ad_manager_api/utils.rb

Overview

Class to keep a list of unique utilities used in order to perform tracking of client library features.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUtilityRegistry

Returns a new instance of UtilityRegistry.



33
34
35
36
37
# File 'lib/ad_manager_api/utils.rb', line 33

def initialize
  @enabled = true
  @registry = Set.new
  @lock = Mutex.new
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



31
32
33
# File 'lib/ad_manager_api/utils.rb', line 31

def enabled
  @enabled
end

Instance Method Details

#add(util) ⇒ Object



51
52
53
# File 'lib/ad_manager_api/utils.rb', line 51

def add(util)
  @lock.synchronize { @registry.add(util) if @enabled }
end

#extract!Object



39
40
41
42
43
44
45
# File 'lib/ad_manager_api/utils.rb', line 39

def extract!
  @lock.synchronize do
    registry = @registry.dup
    @registry.clear
    return registry
  end
end

#lengthObject



47
48
49
# File 'lib/ad_manager_api/utils.rb', line 47

def length
  @lock.synchronize { @registry.length }
end