Class: Flipper::Registry
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/flipper/registry.rb
Defined Under Namespace
Classes: DuplicateKey, Error, MissingKey
Instance Method Summary
collapse
Constructor Details
#initialize(source = {}) ⇒ Registry
Returns a new instance of Registry.
9
10
11
12
|
# File 'lib/flipper/registry.rb', line 9
def initialize(source = {})
@mutex = Mutex.new
@source = source
end
|
Instance Method Details
#add(key, value) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/flipper/registry.rb', line 22
def add(key, value)
@mutex.synchronize do
if @source[key]
raise DuplicateKey, "#{key} is already registered"
else
@source[key] = value
end
end
end
|
#clear ⇒ Object
42
43
44
|
# File 'lib/flipper/registry.rb', line 42
def clear
@mutex.synchronize { @source.clear }
end
|
#each(&block) ⇒ Object
38
39
40
|
# File 'lib/flipper/registry.rb', line 38
def each(&block)
@mutex.synchronize { @source.dup }.each(&block)
end
|
#get(key) ⇒ Object
32
33
34
35
36
|
# File 'lib/flipper/registry.rb', line 32
def get(key)
@mutex.synchronize do
@source[key]
end
end
|
#keys ⇒ Object
14
15
16
|
# File 'lib/flipper/registry.rb', line 14
def keys
@mutex.synchronize { @source.keys }
end
|
#values ⇒ Object
18
19
20
|
# File 'lib/flipper/registry.rb', line 18
def values
@mutex.synchronize { @source.values }
end
|