class Ki::ServiceRegistry

Attributes

by_parent[R]

Public Class Methods

new() click to toggle source
# File lib/util/service_registry.rb, line 23
def initialize
  @monitor = Monitor.new
  @by_parent = {}
end

Public Instance Methods

clear() click to toggle source
Calls superclass method
# File lib/util/service_registry.rb, line 71
def clear
  @monitor.synchronize do
    @by_parent.clear
    super
  end
end
find(url, value=nil) click to toggle source
# File lib/util/service_registry.rb, line 46
def find(url, value=nil)
  @monitor.synchronize do
    if include?(url)
      self[url]
    elsif @by_parent.include?(url)
      services = @by_parent[url]
      if services
        if value
          services = services.select { |id, service| service.supports?(value) }
        end
        services = ServiceList.new.concat(services)
      end
      services
    end
  end
end
find!(url, value=nil) click to toggle source
# File lib/util/service_registry.rb, line 63
def find!(url, value=nil)
  found = find(url, value)
  if found.nil?
    raise "Could not resolve '#{url}'"
  end
  found
end
register(*args) click to toggle source
# File lib/util/service_registry.rb, line 28
def register(*args)
  @monitor.synchronize do
    case args.size
      when 1
        args.first.each_pair do |url, clazz|
          register(url, clazz)
        end
      when 2
        url, clazz = args
        self[url]=clazz
        (@by_parent[File.dirname(url)]||=Array.new) << args
      else
        raise "Not supported '#{args.inspect}'"
    end
  end
  self
end