Class: Irc::Bot::Registry
- Inherits:
-
Object
- Object
- Irc::Bot::Registry
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/registry/dbm.rb,
/home/apoc/projects/ruby/rbot/lib/rbot/registry/tc.rb,
/home/apoc/projects/ruby/rbot/lib/rbot/registry/daybreak.rb,
/home/apoc/projects/ruby/rbot/lib/rbot/registry/sqlite.rb,
/home/apoc/projects/ruby/rbot/lib/rbot/registry.rb
Defined Under Namespace
Classes: AbstractAccessor, DBMAccessor, DaybreakAccessor, SqliteAccessor, TokyoCabinetAccessor
Class Method Summary (collapse)
-
+ (Object) formats
Helper method that will return a list of supported registry formats.
Instance Method Summary (collapse)
-
- (Object) create(path, filename)
Creates a new Accessor object for the specified database filename.
-
- (Object) discover
Returns a list of supported registry database formats.
-
- (Registry) initialize(format = nil)
constructor
Dynamically loads the specified registry type library.
-
- (Object) migrate_registry_folder(path)
Will detect tokyocabinet registry location: ~/.rbot/registry/*.tdb and move it to its new location ~/.rbot/registry_tc/*.tdb.
Constructor Details
- (Registry) initialize(format = nil)
Dynamically loads the specified registry type library.
56 57 58 59 60 |
# File '/home/apoc/projects/ruby/rbot/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 end |
Class Method Details
+ (Object) formats
Helper method that will return a list of supported registry formats.
82 83 84 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/registry.rb', line 82 def self.formats @@formats ||= Registry.new.discover end |
Instance Method Details
- (Object) create(path, filename)
Creates a new Accessor object for the specified database filename.
70 71 72 73 74 75 76 77 78 79 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/registry.rb', line 70 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.optimize db end |
- (Object) discover
Returns a list of supported registry database formats.
63 64 65 66 67 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/registry.rb', line 63 def discover Dir.glob(File.join(@libpath, '*.rb')).map do |name| File.basename(name, File.extname(name)) end end |
- (Object) migrate_registry_folder(path)
Will detect tokyocabinet registry location: ~/.rbot/registry/*.tdb
and move it to its new location ~/.rbot/registry_tc/*.tdb
88 89 90 91 92 93 94 95 96 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/registry.rb', line 88 def migrate_registry_folder(path) old_name = File.join(path, 'registry') new_name = File.join(path, 'registry_tc') if @format == 'tc' and File.exists?(old_name) and not File.exists?(new_name) and not Dir.glob(File.join(old_name, '*.tdb')).empty? File.rename(old_name, new_name) end end |