Class: SplitIoClient::SplitFactoryRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/split_factory_registry.rb

Overview

This class manages configuration options for the split client library. If not custom configuration is required the default configuration values will be used

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSplitFactoryRegistry

Returns a new instance of SplitFactoryRegistry.



22
23
24
# File 'lib/splitclient-rb/split_factory_registry.rb', line 22

def initialize
  @api_keys_hash = Hash.new
end

Instance Attribute Details

#api_keys_hashObject

Returns the value of attribute api_keys_hash.



20
21
22
# File 'lib/splitclient-rb/split_factory_registry.rb', line 20

def api_keys_hash
  @api_keys_hash
end

Instance Method Details

#active_factoriesObject



51
52
53
# File 'lib/splitclient-rb/split_factory_registry.rb', line 51

def active_factories
  @api_keys_hash.length
end

#add(api_key) ⇒ Object



26
27
28
29
30
31
# File 'lib/splitclient-rb/split_factory_registry.rb', line 26

def add(api_key)
  return unless api_key

  @api_keys_hash[api_key] = 0 unless @api_keys_hash[api_key]
  @api_keys_hash[api_key] += 1
end

#number_of_factories_for(api_key) ⇒ Object



40
41
42
43
44
45
# File 'lib/splitclient-rb/split_factory_registry.rb', line 40

def number_of_factories_for(api_key)
  return 0 unless api_key
  return 0 unless @api_keys_hash.key?(api_key)

  @api_keys_hash[api_key]
end

#other_factoriesObject



47
48
49
# File 'lib/splitclient-rb/split_factory_registry.rb', line 47

def other_factories
  return !@api_keys_hash.empty?
end

#redundant_active_factoriesObject



55
56
57
58
59
60
61
# File 'lib/splitclient-rb/split_factory_registry.rb', line 55

def redundant_active_factories
  to_return = 0

  @api_keys_hash.each { |key| to_return += (key[1]-1) }

  to_return
end

#remove(api_key) ⇒ Object



33
34
35
36
37
38
# File 'lib/splitclient-rb/split_factory_registry.rb', line 33

def remove(api_key)
  return unless api_key

  @api_keys_hash[api_key] -= 1 if @api_keys_hash[api_key]
  @api_keys_hash.delete(api_key) if @api_keys_hash[api_key] == 0
end