Class: Gallus::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/gallus/repository.rb

Constant Summary collapse

PARENT_DELIMITER =
'::'

Class Method Summary collapse

Class Method Details

.allObject



7
8
9
# File 'lib/gallus/repository.rb', line 7

def self.all
  @all ||= {}
end

.delete_with_children(name) ⇒ Object



23
24
25
26
27
28
# File 'lib/gallus/repository.rb', line 23

def self.delete_with_children(name)
  @mutex.synchronize do
    all.keys.each { |k| all.delete(k) if k.start_with?(name + PARENT_DELIMITER) }
    all.delete(name)
  end
end

.find_parent(name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gallus/repository.rb', line 11

def self.find_parent(name)
  parent, name = nil, name.dup

  while parent.nil?
    name = name.split(PARENT_DELIMITER)[0..-2].join(PARENT_DELIMITER)
    parent = all[name]
    break if name.empty?
  end

  parent
end

.get_or_create_logger(name, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gallus/repository.rb', line 30

def self.get_or_create_logger(name, &block)
  name, log = name.to_s, nil

  @mutex.synchronize do
    unless log = all[name]
      all[name] = (log = Class.new(Log).new(find_parent(name), name, &block))
    end
  end

  log
end