Module: Alf::Support::Registry

Instance Method Summary collapse

Instance Method Details

#each(&bl) ⇒ Object


22
23
24
# File 'lib/alf/support/registry.rb', line 22

def each(&bl)
  registered.each(&bl)
end

#listen(&listener) ⇒ Object


9
10
11
12
13
14
15
# File 'lib/alf/support/registry.rb', line 9

def listen(&listener)
  listeners << listener
  registered.each do |what|
    method_name, factory = Registry.decode_registered(what)
    listener.call(method_name, factory)
  end
end

#listenersObject


5
6
7
# File 'lib/alf/support/registry.rb', line 5

def listeners
  @listeners ||= []
end

#register(what, registry) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/alf/support/registry.rb', line 26

def register(what, registry)
  method_name, factory = Registry.decode_registered(what)
  (class << registry; self; end).
    send(:define_method, method_name) do |*args, &block|
      factory.new(*args, &block)
    end
  registry.module_eval do
    registered << what
    listeners.each{|l| l.call(method_name, factory) }
  end
end

#registeredObject Also known as: all


17
18
19
# File 'lib/alf/support/registry.rb', line 17

def registered
  @registered ||= []
end