Sha256: 46d0582284d574681e717028d485144267fb74af3ffa51b19062049ac185896d

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

# Copyright 2008-2011 Red Hat, Inc, and individual contributors.
# 
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
# 
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.

module TorqueBox
  class Kernel

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

    # blocks are not allowed on the method named :[]
    def self.[](name)
      self.lookup(name)
    end

    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

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
torquebox-base-1.1.1-java lib/torquebox/kernel.rb
torquebox-base-1.1-java lib/torquebox/kernel.rb
torquebox-base-1.0.1-java lib/torquebox/kernel.rb
torquebox-base-1.0.0-java lib/torquebox/kernel.rb
torquebox-base-1.0.0.CR2-java lib/torquebox/kernel.rb
torquebox-base-1.0.0.CR1-java lib/torquebox/kernel.rb