class Irc::Bot::Registry

Public Class Methods

formats() click to toggle source

Helper method that will return a list of supported registry formats.

# File lib/rbot/registry.rb, line 86
def self.formats
  @@formats ||= Registry.new.discover
end
new(format=nil) click to toggle source

Dynamically loads the specified registry type library.

# File lib/rbot/registry.rb, line 56
def initialize(format=nil)
  @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

Public Instance Methods

create(path, filename) click to toggle source

Creates a new Accessor object for the specified database filename.

# File lib/rbot/registry.rb, line 79
def create(path, filename)
  db = @accessor_class.new(File.join(path, 'registry_' + @format, filename.downcase))
  db.optimize
  db
end
discover() click to toggle source

Returns a list of supported registry database formats.

# File lib/rbot/registry.rb, line 72
def discover
  Dir.glob(File.join(@libpath, '*.rb')).map do |name|
    File.basename(name, File.extname(name))
  end
end
migrate_registry_folder(path) click to toggle source

Will detect tokyocabinet registry location: ~/.rbot/registry/*.tdb

and move it to its new location ~/.rbot/registry_tc/*.tdb
# File lib/rbot/registry.rb, line 92
def migrate_registry_folder(path)
  old_name = File.join(path, 'registry')
  new_name = File.join(path, 'registry_tc')
  if @format == 'tc' and File.exist?(old_name) and
      not File.exist?(new_name) and
      not Dir.glob(File.join(old_name, '*.tdb')).empty?
    File.rename(old_name, new_name)
  end
end