Class: Threatinator::PluginLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/threatinator/plugin_loader.rb

Instance Method Summary collapse

Constructor Details

#initializePluginLoader

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.

Yields:

  • (type, name, plugin)

Yield Parameters:

  • type (Symbol)
  • name (Symbol)
  • plugin (Object)


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.

Parameters:

  • type (#to_sym)
  • name (#to_sym)

Returns:

  • (Object)

    plugin



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_pluginsThreatinator::PluginLoader

Loads all plugins

Returns:



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

Parameters:

  • type (#to_sym)

Returns:



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.

Parameters:

  • type (#to_sym)
  • name (#to_sym)
  • plugin (Object)

Raises:



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

#typesArray<Symbol>

Returns an array of all the types of plugins that are loaded.

Returns:

  • (Array<Symbol>)


55
56
57
# File 'lib/threatinator/plugin_loader.rb', line 55

def types
  @plugin_types_registry.keys
end