X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fregistry.rb;h=61d4b33e02ef454d8cebcfb52617d53bc1f9eef0;hb=cc241a9709593491b6a67810ed8a5a5054e19208;hp=5e905ebb9408ba9774ce2ad3f43fddd925c59824;hpb=836cf49c210ebfeb443861d26379a81b333c2c78;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb index 5e905ebb..61d4b33e 100644 --- a/lib/rbot/registry.rb +++ b/lib/rbot/registry.rb @@ -57,6 +57,15 @@ class Registry @libpath = File.join(File.dirname(__FILE__), 'registry') @format = format load File.join(@libpath, @format+'.rb') if format + # The get_impl method will return all implementations of the + # abstract accessor interface, since we only ever load one + # (the configured one) accessor implementation, we can just assume + # it to be the correct accessor to use. + accessors = AbstractAccessor.get_impl + if accessors.length > 1 + warning 'multiple accessor implementations loaded!' + end + @accessor_class = accessors.first end # Returns a list of supported registry database formats. @@ -68,12 +77,7 @@ class Registry # Creates a new Accessor object for the specified database filename. def create(path, filename) - # The get_impl method will return a list of all the classes that - # implement the accessor interface, since we only ever load one - # (the configured one) accessor implementation, we can just assume - # it to be the correct accessor to use. - cls = AbstractAccessor.get_impl.first - db = cls.new(File.join(path, 'registry_' + @format, filename.downcase)) + db = @accessor_class.new(File.join(path, 'registry_' + @format, filename.downcase)) db.optimize db end @@ -106,7 +110,7 @@ class Registry attr_accessor :recovery def initialize(filename) - debug 'init registry accessor for: ' + filename + debug "init registry accessor of #{self.class} for: #{filename}" @filename = filename @name = File.basename filename @registry = nil @@ -330,7 +334,7 @@ class Registry # Returns all classes from the namespace that implement this interface def self.get_impl - ObjectSpace.each_object(Class).select { |klass| klass < self } + ObjectSpace.each_object(Class).select { |klass| klass.ancestors[1] == self } end end