Sha256: fb96b701748cb13e1600eb52341a96f4a1ef813174d2f3711416a963942802cf
Contents?: true
Size: 981 Bytes
Versions: 8
Compression:
Stored size: 981 Bytes
Contents
module Teaspoon module Registry def self.extended(host) host.instance_variable_set(:@registry, {}) host.instance_variable_set(:@options, {}) end def not_found_in_registry(klass) @not_found_exception = klass end def register(name, constant, path, options = {}) @registry[normalize_name(name)] = proc { require path constant.constantize } @options[normalize_name(name)] = options end def fetch(name) if !(driver = @registry[normalize_name(name)]) raise not_found_exception.new(name: name, available: available.keys) end driver.call end def equal?(one, two) normalize_name(one) == normalize_name(two) end def available @options end private def normalize_name(name) name.to_s.gsub(/[-|\s]/, '_').to_sym end def not_found_exception @not_found_exception || Teaspoon::NotFoundInRegistry end end end
Version data entries
8 entries across 8 versions & 1 rubygems