Class: Flipper::Registry
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/flipper/registry.rb
Overview
Internal: Used to store registry of groups by name.
Defined Under Namespace
Classes: DuplicateKey, Error, KeyNotFound
Instance Method Summary
collapse
Constructor Details
#initialize(source = {}) ⇒ Registry
Returns a new instance of Registry.
21
22
23
24
|
# File 'lib/flipper/registry.rb', line 21
def initialize(source = {})
@mutex = Mutex.new
@source = source
end
|
Instance Method Details
#add(key, value) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/flipper/registry.rb', line 34
def add(key, value)
key = key.to_sym
@mutex.synchronize do
if @source[key]
raise DuplicateKey, "#{key} is already registered"
else
@source[key] = value
end
end
end
|
#clear ⇒ Object
64
65
66
|
# File 'lib/flipper/registry.rb', line 64
def clear
@mutex.synchronize { @source.clear }
end
|
#each(&block) ⇒ Object
60
61
62
|
# File 'lib/flipper/registry.rb', line 60
def each(&block)
@mutex.synchronize { @source.dup }.each(&block)
end
|
#get(key) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/flipper/registry.rb', line 46
def get(key)
key = key.to_sym
@mutex.synchronize do
@source[key]
end
end
|
#key?(key) ⇒ Boolean
53
54
55
56
57
58
|
# File 'lib/flipper/registry.rb', line 53
def key?(key)
key = key.to_sym
@mutex.synchronize do
@source.key?(key)
end
end
|
#keys ⇒ Object
26
27
28
|
# File 'lib/flipper/registry.rb', line 26
def keys
@mutex.synchronize { @source.keys }
end
|
#values ⇒ Object
30
31
32
|
# File 'lib/flipper/registry.rb', line 30
def values
@mutex.synchronize { @source.values }
end
|