class Dogviz::Registry

Public Class Methods

new(context) click to toggle source
# File lib/dogviz/registry.rb, line 7
def initialize(context)
  @context = context
  @by_name = {}
  @all = []
end

Public Instance Methods

find(&matcher) click to toggle source
# File lib/dogviz/registry.rb, line 22
def find(&matcher)
  raise LookupError.new(@context, "need to provide match block") unless block_given?
  @all.find(&matcher)
end
find_all(&matcher) click to toggle source
# File lib/dogviz/registry.rb, line 27
def find_all(&matcher)
  raise MissingMatchBlockError.new(@context) unless block_given?
  @all.select(&matcher)
end
lookup(name) click to toggle source
# File lib/dogviz/registry.rb, line 32
def lookup(name)
  found = @by_name[name]
  raise LookupError.new(@context, "could not find '#{name}'") if found.nil?
  raise found if found.is_a?(Exception)
  found
end
register(name, thing) click to toggle source
# File lib/dogviz/registry.rb, line 13
def register(name, thing)
  @all << thing
  if @by_name.has_key?(name)
    @by_name[name] = DuplicateLookupError.new @context, name
  else
    @by_name[name] = thing
  end
end