Add the names to the list of plugins that will not be loaded. This list prevents the plugin system from loading unwanted or unneeded plugins.
If a plugin name appears in both the 'disregard_plugin' list and the 'plugin' list, the disregard list takes precedence; that is, the plugin will not be loaded.
# File lib/little-plugger.rb, line 137 def disregard_plugin( *names ) @disregard_plugin ||= [] @disregard_plugin.concat(names.map! {|n| n.to_sym}) @disregard_plugin end
Iterate over the loaded plugin classes and modules and call the initialize
method for each plugin. The plugin's initialize method is defeind as
initialize_plugin_name
, where the plugin name is unique to
each plugin.
# File lib/little-plugger.rb, line 175 def initialize_plugins plugins.each do |name, klass| msg = "initialize_#{name}" klass.send msg if klass.respond_to? msg end end
Iterate through all installed gems looking for those that have the
plugin_path
in their “lib” folder, and load all .rb files
found in the gem's plugin path. Each .rb file should define one class
or module that will be used as a plugin.
# File lib/little-plugger.rb, line 187 def load_plugins @loaded ||= {} found = {} Gem.find_files(File.join(plugin_path, '*.rb')).sort!.reverse_each do |path| name = File.basename(path, '.rb').to_sym found[name] = path unless found.key? name end :keep_on_truckin while found.map { |name, path| next unless plugin_names.empty? or plugin_names.include? name next if disregard_plugins.include? name next if @loaded[name] begin @loaded[name] = load path rescue ScriptError, StandardError => err warn "Error loading #{path.inspect}: #{err.message}. skipping..." end }.any? end
Add the names to the list of plugins that will be loaded.
# File lib/little-plugger.rb, line 125 def plugin( *names ) plugin_names.concat(names.map! {|n| n.to_sym}) end
This module or class where plugins are located.
# File lib/little-plugger.rb, line 216 def plugin_module ::LittlePlugger.default_plugin_module(plugin_path) end
Returns the array of plugin names that will be loaded. If the array is
empty, then any plugin found in the plugin_path
will be
loaded.
# File lib/little-plugger.rb, line 147 def plugin_names @plugin_names ||= [] end
The path to search in a gem's 'lib' folder for plugins.
# File lib/little-plugger.rb, line 210 def plugin_path ::LittlePlugger.default_plugin_path(self) end
Loads the desired plugins and returns a hash. The hash contains all the plugin classes and modules keyed by the plugin name.
# File lib/little-plugger.rb, line 154 def plugins load_plugins pm = plugin_module names = pm.constants.map { |s| s.to_s } names.reject! { |n| n =~ /^[A-Z_]+$/ } h = {} names.each do |name| sym = ::LittlePlugger.underscore(name).to_sym next unless plugin_names.empty? or plugin_names.include? sym next if disregard_plugins.include? sym h[sym] = pm.const_get name end h end