lib/plugin_manager.rb in plugin_manager-1.4 vs lib/plugin_manager.rb in plugin_manager-1.5

- old
+ new

@@ -6,30 +6,53 @@ require 'plugin_manager/definition_builder' class PluginManager attr_reader :unreadable_definitions, :plugins_with_errors, :loaded_plugins, :unloaded_plugins, :output + # A list of plugins that should not be loaded. You can feel free to assign + # plugins that are dependencies of plugins that are not disabled. In that + # case the plugin manager will just ignore your request to disable the + # plugin. This ensures that you only disable plugins in such a way that it is + # stable to the system. + attr_writer :disabled_plugins + class << self attr_accessor :current end def initialize(output = STDOUT) @plugins = [] @unloaded_plugins = [] @loaded_plugins = [] @unreadable_definitions = [] @plugins_with_errors = [] + @disabled_plugins = [] @output = output end def on_load(&block) @load_observer = block end def plugins @plugins end + + # A subset of the plugins that have been requested to be disabled. + def disabled_plugins + plugins.find_all do |pd| + @disabled_plugins.include?(pd.name) && + derivative_plugins_for(pd).all? {|der| @disabled_plugins.include? der.name} + end + end + + # Returns all plugins that are dependent on the given plugin + def derivative_plugins_for(plugin) + plugins.find_all do |pd| + pd.dependencies.any? {|dep| dep.required_name == plugin.name} + end + end def plugin_objects @loaded_plugins.map {|definition| definition.object} end @@ -116,9 +139,13 @@ @plugins = @plugins.sort_by {|pl| pl.name } @unloaded_plugins = @unloaded_plugins.sort_by {|pl| pl.name } end def load(*plugin_names) + # Make sure disabled plugins are not listed as unloaded so we don't + # try to load them. + @unloaded_plugins -= disabled_plugins + if plugin_names.empty? return load_maximal else target_dependencies = plugin_names.map do |n| unless result = latest_version_by_name(n)