Class: Wbem::ClassFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/wbem/class_factory.rb

Constant Summary collapse

MOFBASE =
"/usr/share/mof/cim-current"
AMTBASE =
"/usr/share/mof/iAMT/MOF"
QUALIFIERS =
"qualifiers.mof"
SCHEMATA =
{ MOFBASE => "CIM_Schema.mof", AMTBASE => "amt.mof" }
CLASSDIR =
"wbem"

Instance Method Summary collapse

Constructor Details

#initialize(basepath = nil) ⇒ ClassFactory

Constructor



23
24
25
# File 'lib/wbem/class_factory.rb', line 23

def initialize basepath = nil
  @basedir = File.expand_path(File.join(basepath || Dir.getwd, CLASSDIR))
end

Instance Method Details

#class_for(name) ⇒ Object

Class Factory



143
144
145
146
147
148
149
150
151
# File 'lib/wbem/class_factory.rb', line 143

def class_for name
  begin
    path = "#{@basedir}/#{name}"
    require path
    return Object.const_get("Wbem").const_get(name)
  rescue LoadError
    raise "'#{path}.rb' not found, use 'genclass' of ruby-wbem to generate class '#{name}'"
  end
end

#gen_class(name) ⇒ Object

gen_class



155
156
157
158
159
160
161
# File 'lib/wbem/class_factory.rb', line 155

def gen_class name
  mofname = name + ".mof"
  classpath = File.join(@basedir, "#{name}.rb")
  parse_with_ancestors name
  generate name, classpath
  class_for name
end