Class: Threatinator::PluginLoader
- Inherits:
-
Object
- Object
- Threatinator::PluginLoader
- Defined in:
- lib/threatinator/plugin_loader.rb
Instance Method Summary collapse
-
#each(type = nil) {|type, name, plugin| ... } ⇒ Object
Enumerates through all plugins, optionally filtered by type.
-
#get(type, name) ⇒ Object
Retrieves a loaded plugin by type and name.
-
#initialize ⇒ PluginLoader
constructor
A new instance of PluginLoader.
-
#load_all_plugins ⇒ Threatinator::PluginLoader
Loads all plugins.
-
#load_plugins(type) ⇒ Threatinator::PluginLoader
Loads all plugins of the specified type.
-
#register_plugin(type, name, plugin) ⇒ Object
Registers a plugin with the provided type and name.
-
#types ⇒ Array<Symbol>
Returns an array of all the types of plugins that are loaded.
Constructor Details
#initialize ⇒ PluginLoader
Returns a new instance of PluginLoader.
7 8 9 |
# File 'lib/threatinator/plugin_loader.rb', line 7 def initialize() @plugin_types_registry = Threatinator::Registry.new end |
Instance Method Details
#each(type = nil) {|type, name, plugin| ... } ⇒ Object
Enumerates through all plugins, optionally filtered by type.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/threatinator/plugin_loader.rb', line 41 def each(type = nil) return enum_for(:each, type) unless block_given? @plugin_types_registry.each do |t, type_registry| unless type.nil? next unless type.to_sym == t end type_registry.each do |name, plugin| yield(t, name, plugin) end end end |
#get(type, name) ⇒ Object
Retrieves a loaded plugin by type and name.
30 31 32 33 34 |
# File 'lib/threatinator/plugin_loader.rb', line 30 def get(type, name) type_registry = @plugin_types_registry.get(type.to_sym) return nil if type_registry.nil? return type_registry.get(name.to_sym) end |
#load_all_plugins ⇒ Threatinator::PluginLoader
Loads all plugins
13 14 15 16 |
# File 'lib/threatinator/plugin_loader.rb', line 13 def load_all_plugins() load_plugins(:*) return self end |
#load_plugins(type) ⇒ Threatinator::PluginLoader
Loads all plugins of the specified type
21 22 23 24 |
# File 'lib/threatinator/plugin_loader.rb', line 21 def load_plugins(type) load_files(find_plugin_files(type.to_sym)) return self end |
#register_plugin(type, name, plugin) ⇒ Object
Registers a plugin with the provided type and name.
64 65 66 67 68 69 70 |
# File 'lib/threatinator/plugin_loader.rb', line 64 def register_plugin(type, name, plugin) type = type.to_sym unless type_registry = @plugin_types_registry.get(type) type_registry = @plugin_types_registry.register(type, Threatinator::Registry.new) end type_registry.register(name.to_sym, plugin) end |
#types ⇒ Array<Symbol>
Returns an array of all the types of plugins that are loaded.
55 56 57 |
# File 'lib/threatinator/plugin_loader.rb', line 55 def types @plugin_types_registry.keys end |