Class: Dtn::Registry
- Inherits:
-
Object
- Object
- Dtn::Registry
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/dtn/registry.rb
Overview
Abstract thread safe registry
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #find(item_name) ⇒ Object (also: #[])
-
#initialize(name:) ⇒ Registry
constructor
A new instance of Registry.
- #register(name, item) ⇒ Object (also: #[]=)
- #registered?(name) ⇒ Boolean
Constructor Details
#initialize(name:) ⇒ Registry
Returns a new instance of Registry.
15 16 17 18 |
# File 'lib/dtn/registry.rb', line 15 def initialize(name:) @name = name @items = Concurrent::Map.new end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/dtn/registry.rb', line 13 def name @name end |
Instance Method Details
#clear ⇒ Object
20 21 22 |
# File 'lib/dtn/registry.rb', line 20 def clear @items.clear end |
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/dtn/registry.rb', line 24 def each(&block) @items.values.uniq.each(&block) end |
#find(item_name) ⇒ Object Also known as: []
28 29 30 31 32 |
# File 'lib/dtn/registry.rb', line 28 def find(item_name) @items.fetch(item_name) rescue KeyError => e raise (e, item_name) end |
#register(name, item) ⇒ Object Also known as: []=
36 37 38 39 40 |
# File 'lib/dtn/registry.rb', line 36 def register(name, item) return unless name @items[name] = item end |
#registered?(name) ⇒ Boolean
44 45 46 |
# File 'lib/dtn/registry.rb', line 44 def registered?(name) @items.key?(name) end |