Parent

Ohai::ProvidesMap

Attributes

map[R]

Public Class Methods

new() click to toggle source
# File lib/ohai/provides_map.rb, line 30
def initialize
  @map = Mash.new
end

Public Instance Methods

all_plugins(attribute_filter=nil) click to toggle source
# File lib/ohai/provides_map.rb, line 105
def all_plugins(attribute_filter=nil)
  if attribute_filter.nil?
    collected = []
    collect_plugins_in(map, collected).uniq
  else
    deep_find_providers_for(Array(attribute_filter))
  end
end
deep_find_providers_for(attributes) click to toggle source

This function is used to fetch the plugins for the attributes specified in the CLI options to Ohai. It first attempts to find the plugins for the attributes or the sub attributes given. If it can’t find any, it looks for plugins that might provide the parents of a given attribute and returns the first parent found.

# File lib/ohai/provides_map.rb, line 70
def deep_find_providers_for(attributes)
  plugins = []
  attributes.each do |attribute|
    attrs = select_subtree(@map, attribute)

    unless attrs
      attrs = select_closest_subtree(@map, attribute)

      unless attrs
        raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'"
      end
    end

    collect_plugins_in(attrs, plugins)
  end

  plugins.uniq
end
find_closest_providers_for(attributes) click to toggle source

This function is used to fetch the plugins from ‘depends “languages”’ statements in plugins. It gathers plugins providing each of the attributes listed, or the plugins providing the closest parent attribute

# File lib/ohai/provides_map.rb, line 93
def find_closest_providers_for(attributes)
  plugins = []
  attributes.each do |attribute|
    parts = normalize_and_validate(attribute)
    raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless @map[parts[0]]
    attrs = select_closest_subtree(@map, attribute)
    raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs
    plugins += attrs[:_plugins]
  end
  plugins.uniq
end
find_providers_for(attributes) click to toggle source

gather plugins providing exactly the attributes listed

# File lib/ohai/provides_map.rb, line 52
def find_providers_for(attributes)
  plugins = []
  attributes.each do |attribute|
    attrs = select_subtree(@map, attribute)
    raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
    raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs[:_plugins]
    plugins += attrs[:_plugins]
  end
  plugins.uniq
end
set_providers_for(plugin, provided_attributes) click to toggle source
# File lib/ohai/provides_map.rb, line 34
def set_providers_for(plugin, provided_attributes)
  unless plugin.kind_of?(Ohai::DSL::Plugin)
    raise ArgumentError, "set_providers_for only accepts Ohai Plugin classes (got: #{plugin})"
  end

  provided_attributes.each do |attribute|
    attrs = @map
    parts = normalize_and_validate(attribute)
    parts.each do |part|
      attrs[part] ||= Mash.new
      attrs = attrs[part]
    end
    attrs[:_plugins] ||= []
    attrs[:_plugins] << plugin
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.