Parent

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 105
def [](key)
  @data[key]
end
[]=(key, value) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 109
def []=(key, value)
  @data[key] = value
end
attribute?(name) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 119
def attribute?(name)
  @data.has_key?(name)
end
each(&block) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 113
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 127
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 136
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 151
def get_attribute(name)
  @data[name]
end
has_run?() click to toggle source
# File lib/ohai/dsl/plugin.rb, line 97
def has_run?
  @has_run
end
hint?(name) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 155
def hint?(name)
  Ohai::Hints.hint?(name)
end
method_missing(name, *args) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 171
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 101
def reset!
  @has_run = false
end
run() click to toggle source
# File lib/ohai/dsl/plugin.rb, line 92
def run
  @has_run = true
  run_plugin
end
safe_run() click to toggle source

emulates the old plugin loading behavior

# File lib/ohai/dsl/plugin.rb, line 160
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 123
def set(name, *value)
  set_attribute(name, *value)
end
set_attribute(name, *values) click to toggle source
# File lib/ohai/dsl/plugin.rb, line 146
def set_attribute(name, *values)
  @data[name] = Array18(*values)
  @data[name]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.