class Irc::Bot::Registry::Accessor

This class provides persistent storage for plugins via a hash interface. The default mode is an object store, so you can store ruby objects and reference them with hash keys. This is because the default store/restore methods of the plugins’ RegistryAccessor are calls to Marshal.dump and Marshal.restore, for example:

blah = Hash.new
blah[:foo] = "fum"
@registry[:blah] = blah

then, even after the bot is shut down and disconnected, on the next run you can access the blah object as it was, with:

blah = @registry[:blah]

The registry can of course be used to store simple strings, fixnums, etc as well, and should be useful to store or cache plugin data or dynamic plugin configuration.

WARNING: in object store mode, don’t make the mistake of treating it like a live object, e.g. (using the example above)

@registry[:blah][:foo] = "flump"

will NOT modify the object in the registry - remember that Registry#[] returns a Marshal.restore’d object, the object you just modified in place will disappear. You would need to:

blah = @registry[:blah]
blah[:foo] = "flump"
@registry[:blah] = blah

If you don’t need to store objects, and strictly want a persistant hash of strings, you can override the store/restore methods to suit your needs, for example (in your plugin):

def initialize
  class << @registry
    def store(val)
      val
    end
    def restore(val)
      val
    end
  end
end

Your plugins section of the registry is private, it has its own namespace (derived from the plugin’s class name, so change it and lose your data). Calls to registry.each etc, will only iterate over your namespace.

This class provides persistent storage for plugins via a hash interface. The default mode is an object store, so you can store ruby objects and reference them with hash keys. This is because the default store/restore methods of the plugins’ RegistryAccessor are calls to Marshal.dump and Marshal.restore, for example:

blah = Hash.new
blah[:foo] = "fum"
@registry[:blah] = blah

then, even after the bot is shut down and disconnected, on the next run you can access the blah object as it was, with:

blah = @registry[:blah]

The registry can of course be used to store simple strings, fixnums, etc as well, and should be useful to store or cache plugin data or dynamic plugin configuration.

WARNING: in object store mode, don’t make the mistake of treating it like a live object, e.g. (using the example above)

@registry[:blah][:foo] = "flump"

will NOT modify the object in the registry - remember that Registry#[] returns a Marshal.restore’d object, the object you just modified in place will disappear. You would need to:

blah = @registry[:blah]
blah[:foo] = "flump"
@registry[:blah] = blah

If you don’t need to store objects, and strictly want a persistant hash of strings, you can override the store/restore methods to suit your needs, for example (in your plugin):

def initialize
  class << @registry
    def store(val)
      val
    end
    def restore(val)
      val
    end
  end
end

Your plugins section of the registry is private, it has its own namespace (derived from the plugin’s class name, so change it and lose your data). Calls to registry.each etc, will only iterate over your namespace.