Class | SSHMenu::ClassMapper |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
The ClassMapper is a singleton object shared by all classes throughout the application. Its job is to map a symbolic name such as ‘app.dialog.host’ to a class name such as SSHMenu::HostDialog.
It is possible to customise the behaviour of the application by ‘injecting’ mappings which cause different parts of the application to be built using custom classes.
It is not generally possible to modify a mapping after it has been injected since objects of the original class may already have been constructed. The reset_mappings method can be used to discard all known mappings, but this is really only useful to the regression test suite.
Takes a symbolic path name such as ‘app.dialog.host’ and returns a class object such as SSHMenu::HostDialog. Throws a RuntimeError if the requested path is not mapped to a class.
# File lib/sshmenu.rb, line 92 def get_class(path) return @class_map[path] if @class_map[path] raise RuntimeError, "Could not find class for path '#{path}' in:\n" + self end
Used to define new mappings. Takes a hash of pathname => classname pairs.
# File lib/sshmenu.rb, line 106 def inject(map) map.keys.each { |k| @class_map[k] = map[k] unless @class_map.key?(k) } end