Class: Dtn::Registry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/dtn/registry.rb

Overview

Abstract thread safe registry

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/dtn/registry.rb', line 13

def name
  @name
end

Instance Method Details

#clearObject



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 key_error_with_custom_message(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

Returns:

  • (Boolean)


44
45
46
# File 'lib/dtn/registry.rb', line 44

def registered?(name)
  @items.key?(name)
end