Ohai plugin loader. Finds all the plugins in your `Ohai::Config` (supports a single or multiple path setting here), evaluates them and returns plugin objects.
Simple struct to track a v6 plugin’s class, file path, and the root of the plugin dir from which it was loaded.
# File lib/ohai/loader.rb, line 65 def load_all plugin_files_by_dir.each do |plugin_file| load_plugin_class(plugin_file.path, plugin_file.plugin_root) end collect_v6_plugins collect_v7_plugins end
Load a specified file as an ohai plugin and creates an instance of it. Not used by ohai itself, but can be used to load a plugin for testing purposes. plugin_dir_path is required when loading a v6 plugin.
# File lib/ohai/loader.rb, line 78 def load_plugin(plugin_path, plugin_dir_path = nil) plugin_class = load_plugin_class(plugin_path, plugin_dir_path) return nil unless plugin_class.kind_of?(Class) case when plugin_class < Ohai::DSL::Plugin::VersionVI load_v6_plugin(plugin_class, plugin_path, plugin_dir_path) when plugin_class < Ohai::DSL::Plugin::VersionVII load_v7_plugin(plugin_class) else raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{plugin_class}" end end
Reads the file specified by `plugin_path` and returns a class object for the ohai plugin defined therein.
If `plugin_dir_path` is given, and the file at `plugin_path` is a v6 plugin, the ‘relative path’ of the plugin (used by `require_plugin()`) is computed by finding the relative path from `plugin_dir_path` to `plugin_path`
# File lib/ohai/loader.rb, line 97 def load_plugin_class(plugin_path, plugin_dir_path=nil) # Read the contents of the plugin to understand if it's a V6 or V7 plugin. contents = "" begin contents << IO.read(plugin_path) rescue IOError, Errno::ENOENT Ohai::Log.warn("Unable to open or read plugin at #{plugin_path}") return nil end # We assume that a plugin is a V7 plugin if it contains Ohai.plugin in its contents. if contents.include?("Ohai.plugin") load_v7_plugin_class(contents, plugin_path) else Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \ Version 6 plugins will not be supported in future releases of Ohai. \ Please upgrade your plugin to version 7 plugin syntax. \ For more information visit here: docs.opscode.com/ohai_custom.html") load_v6_plugin_class(contents, plugin_path, plugin_dir_path) end end
Searches all plugin paths and returns an Array of PluginFile objects representing each plugin file.
# File lib/ohai/loader.rb, line 59 def plugin_files_by_dir Array(Ohai::Config[:plugin_path]).inject([]) do |plugin_files, plugin_path| plugin_files + PluginFile.find_all_in(plugin_path) end end
Generated with the Darkfish Rdoc Generator 2.