class Ohai::DSL::Plugin

Attributes

data[R]

Public Class Methods

new(data) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 87
def initialize(data)
  @data = data
  @has_run = false
end

Public Instance Methods

[](key) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 110
def [](key)
  @data[key]
end
[]=(key, value) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 114
def []=(key, value)
  @data[key] = value
end
attribute?(name)
Alias for: has_key?
each(&block) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 118
def each(&block)
  @data.each do |key, value|
    block.call(key, value)
  end
end
from(cmd) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 134
def from(cmd)
  _status, stdout, _stderr = run_command(:command => cmd)
  return "" if stdout.nil? || stdout.empty?
  stdout.strip
end
from_with_regex(cmd, *regex_list) click to toggle source

Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is\ the value.

# File lib/ohai/dsl/plugin.rb, line 143
def from_with_regex(cmd, *regex_list)
  regex_list.flatten.each do |regex|
    _status, stdout, _stderr = run_command(:command => cmd)
    return "" if stdout.nil? || stdout.empty?
    stdout.chomp!.strip
    md = stdout.match(regex)
    return md[1]
  end
end
get_attribute(name) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 158
def get_attribute(name)
  @data[name]
end
has_key?(name) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 124
def has_key?(name)
  @data.has_key?(name)
end
Also aliased as: attribute?
has_run?() click to toggle source
# File lib/ohai/dsl/plugin.rb, line 102
def has_run?
  @has_run
end
hint?(name) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 162
def hint?(name)
  Ohai::Hints.hint?(name)
end
method_missing(name, *args) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 178
def method_missing(name, *args)
  return get_attribute(name) if args.length == 0

  set_attribute(name, *args)
end
reset!() click to toggle source
# File lib/ohai/dsl/plugin.rb, line 106
def reset!
  @has_run = false
end
run() click to toggle source
# File lib/ohai/dsl/plugin.rb, line 92
def run
  @has_run = true

  if Ohai::Config[:disabled_plugins].include?(name)
    Ohai::Log.debug("Skipping disabled plugin #{name}")
  else
    run_plugin
  end
end
safe_run() click to toggle source

emulates the old plugin loading behavior

# File lib/ohai/dsl/plugin.rb, line 167
def safe_run
  begin
    self.run
  rescue Ohai::Exceptions::Error => e
    raise e
  rescue => e
    Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
    e.backtrace.each { |line| Ohai::Log.debug( line )}
  end
end
set(name, *value) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 130
def set(name, *value)
  set_attribute(name, *value)
end
set_attribute(name, *values) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 153
def set_attribute(name, *values)
  @data[name] = Array18(*values)
  @data[name]
end

Private Instance Methods

Array18(*args) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 186
def Array18(*args)
  return nil if args.empty?
  return args.first if args.length == 1
  return *args
end