Class: DfpApi::Utils::UtilityRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dfp_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

#initialize ⇒ UtilityRegistry

Returns a new instance of UtilityRegistry.



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

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

Instance Attribute Details

#enabled ⇒ Object

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

Instance Method Details

#add(util) ⇒ Object



51
52
53
# File 'lib/dfp_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/dfp_api/utils.rb', line 39

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

#length ⇒ Object



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

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