| Module | Joyau::Init |
| In: |
ruby/site_ruby/joyau/init.rb
|
This module allows to inits some services, and to stop them easily :
require 'joyau/init' Joyau.init(:intrafont, :audio) # Do something Joyau.stop
This is a simple use, but notice that dependencies are managed: Joyau.initLib as well as Joyau.initGfx are run, because Intrafont depends on them.
The default modules are:
Every module you load through Joyau.init is stopped when Joyau.stop. You can stop module during your program’s execution as well:
Joyau.stop(:something, :another_mod) # Stops :something and :another_mod Joyau.stop # Stops everything
If you created a module, you can make it loadable through this interface:
class MyModule
def self.init; puts "My module has been inited !"
def self.stop; puts "My module has been stopped !"
end
Joyau::Init.register(:my_module, MyModule.method(:init),
MyModule.method(:stop))
Joyau.init(:my_module) # My module has been inited !
Joyau.stop # My module has been stopped !
If your module depends on something, you can specify the symbols of these:
Joyau::Init.register(:mod, init_func, stop_func, :dep1, :dep2, ...)
Inits the given module.
# File ruby/site_ruby/joyau/init.rb, line 85 def init(*modules) begin modules.each do |mod| unless @modules[mod].initialized? @modules[mod].dependencies.each { |dep| init(dep) } @modules[mod].init end end rescue NoMethodError raise UndefinedModule, "one of the specified module or one of its dependencies does not exist" end end
Registers a new module
# File ruby/site_ruby/joyau/init.rb, line 113 def register(symbol, init_func, stop_func, *deps) @modules[symbol] = Init::Module.new(init_func, stop_func, deps) end
Stops the given modules, or all the module if no module name is given.
# File ruby/site_ruby/joyau/init.rb, line 100 def stop(*args) begin if args.size == 0 @modules.each { |key, mod| mod.stop } else args.each { |mod| @modules[mod].stop } end rescue NoMethodError raise UndefinedModule, "one of the specified module does not exist" end end