class Pluginator::Autodetect
Add autodetection capabilities to Group
@see Group
, FormattedFinder
Public Class Methods
new(group, options={})
click to toggle source
Automatically load plugins for given group (and type)
@param group [String] name of the plugins group @param options [Hash] options to pass to creating Pluginator
instance @option type [String] name of the plugin type @option prefix [String] a prefix for finding plugins if forcing,
by default only `/lib` is checked, regexp notation is allowed, for example `/(lib|local_lib)`
Calls superclass method
# File lib/pluginator/autodetect.rb, line 45 def initialize(group, options={}) super(group) @force_prefix = options[:prefix] @force_type = options[:type] refresh end
Public Instance Methods
refresh()
click to toggle source
Initiate another lookup for plugins
-
does not clean the state
-
does not resolve all gems, only the new ones
Use it after gem list change, for example after `Gem.install(“new_gem”)`
# File lib/pluginator/autodetect.rb, line 57 def refresh plugin_lists = FormattedFinder.new(@force_prefix, @group, @force_type) register_plugins(plugin_lists.loaded_plugins_path) load_plugins(plugin_lists.load_path_plugins_paths) activate_plugins(plugin_lists.gem_plugins_paths) end
type()
click to toggle source
Return the forced type
# File lib/pluginator/autodetect.rb, line 65 def type @plugins[@force_type] unless @force_type.nil? end
Private Instance Methods
activate_plugins(plugins_to_activate)
click to toggle source
# File lib/pluginator/autodetect.rb, line 86 def activate_plugins(plugins_to_activate) selected = active_or_latest_gems_matching(plugins_to_activate.map(&:first).compact) plugins_to_activate.each do |gemspec, path, name, type| next unless selected.include?(gemspec) gemspec.activate require path register_plugin(type, name2class(name)) end end
active_or_latest_gems_matching(specifications)
click to toggle source
filter active / latest gem versions
# File lib/pluginator/autodetect.rb, line 97 def active_or_latest_gems_matching(specifications) specifications.group_by(&:name).map do |_name, plugin_specifications| active_or_latest_gemspec(plugin_specifications.sort) end end
active_or_latest_gemspec(specifications)
click to toggle source
find active or latest gem in given set
# File lib/pluginator/autodetect.rb, line 104 def active_or_latest_gemspec(specifications) specifications.find(&:activated) || specifications.last end
load_plugins(plugins_to_load)
click to toggle source
# File lib/pluginator/autodetect.rb, line 79 def load_plugins(plugins_to_load) plugins_to_load.each do |path, name, type| require path register_plugin(type, name2class(name)) end end
register_plugins(plugins_to_register)
click to toggle source
# File lib/pluginator/autodetect.rb, line 73 def register_plugins(plugins_to_register) plugins_to_register.each do |name, type| register_plugin(type, name2class(name)) end end