Method: Ruber::Application#safe_load_plugins

Defined in:
lib/ruber/application/application.rb

#safe_load_plugins(plugins, silent = false, dirs = nil) {|pso, ex| ... } ⇒ Boolen

Loads plugins handling the exceptions they may raise in the meanwhile

It is a wrapper around ComponentManager#load_plugins.

If it’s given a block, it simply calls ComponentManager#load_plugins passing it the block.

If no block is given, the behaviour in case of an exception depends on the silent argument:

  • if true, then the error will be silently ignored and the component manager will go on loading the remaining plugins. Errors caused by those will be ignored as well

  • if false, the user will be shown a ComponentLoadingErrorDialog. According to what the user chooses in the dialog, the component manager will behave in a different way, as described in ComponentManager#load_plugins

Note: this method doesn’t attempt to handle exceptions raised while computing or sorting dependencies.

Parameters:

  • plugins (Array<Symbol>)

    the names of the plugins to load. It doesn’t need to include dependencies, as they’re computed automatically

  • silent (Boolean) (defaults to: false)

    whether errors while loading plugins should be silently ignored or not

  • dirs (Array<String>, nil) (defaults to: nil)

    the directories where to look for plugins. If nil, then the value returned by #plugin_directories will be used

Yields:

  • (pso, ex)

    block called when loading a plugin raises an exception

Yield Parameters:

  • pso (PluginSpecification)

    the plugin specification object associated with the plugin which raised the exception

  • ex (Exception)

    the exception raised while loading the plugin

Returns:

  • (Boolen)

    true if the plugins were loaded successfully and false otherwise

See Also:


246
247
248
249
250
251
252
253
# File 'lib/ruber/application/application.rb', line 246

def safe_load_plugins plugins, silent = false, dirs = nil, &blk
  if blk.nil? and silent then blk = proc{|_pl, _e| :silent}
  elsif blk.nil?
    blk = Proc.new{|pl, e| ComponentLoadingErrorDialog.new(pl.name, e, nil).exec}
  end
  @components.load_plugins plugins, dirs || @plugin_dirs, &blk
  
end