Class: Ali::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable, MonitorMixin, Singleton
Defined in:
lib/ali/registry.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/ali/registry.rb', line 21

def [](key)
  scynchronize { dictionary[key.to_s] }
end

#eachObject



25
26
27
28
29
# File 'lib/ali/registry.rb', line 25

def each
  synchronize do
    dictionary.each { |key, task| yield key, task }
  end
end

#register(task) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ali/registry.rb', line 13

def register(task)
  synchronize do
    key = task.name(for: :registry)
    raise Error, "Task #{key} already exists!" if dictionary.key?(key)
    dictionary[key] = task
  end
end

#to_aObject



31
32
33
# File 'lib/ali/registry.rb', line 31

def to_a
  synchronize { dictionary.values }
end