Class: TorqueBox::Kernel

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/kernel.rb

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

blocks are not allowed on the method named :[]



32
33
34
# File 'lib/torquebox/kernel.rb', line 32

def self.[](name)
  self.lookup(name)
end

.blocksObject



51
52
53
# File 'lib/torquebox/kernel.rb', line 51

def self.blocks
  @blocks ||= Hash.new{|h, k| h[k] = []}
end

.kernel=(kernel) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/torquebox/kernel.rb', line 21

def self.kernel=(kernel)
  @kernel = kernel 
  blocks.keys.each do |name|
    blocks.delete(name).each do |block|
      lookup name, &block
    end
  end
  @kernel
end

.lookup(name, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/torquebox/kernel.rb', line 36

def self.lookup(name, &block)
  if @kernel.nil?
    self.blocks[name] << block
    nil
  else
    entry = @kernel.getRegistry().findEntry(name)      
    return nil unless entry
    if block_given?
      yield entry.getTarget()
    else
      entry.getTarget()
    end
  end
end