Class: Cmpi::CMPIInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/cmpi.rb,
ext/cmpi-bindings/cmpi_wrap.c

Overview

Proxy of C Cmpi::CMPIInstance struct

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Allow Instance.Property and Instance.Property=



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/cmpi.rb', line 332

def method_missing name, *args
  s = name.to_s
  if s =~ /=$/
	v = args[0]
	n = s.chop
	# -> http://blog.sidu.in/2008/02/loading-classes-from-strings-in-ruby.html
    unless @typemap
      begin
        @typemap = Cmpi.const_get(self.objectpath.classname).typemap
      rescue NoMethodError
        raise "Cmpi::#{self.objectpath.classname}.typemap not defined"
      end
    end
	t = @typemap[n]
    raise "Property '#{n}' of Cmpi::#{self.objectpath.classname}.typemap not defined" unless t
#        STDERR.printf "Instance.%s = %s[%s]:%04x\n" % [n, v, v.class, t]
    self[n,v] = t
  else
#	STDERR.puts "CMPIInstance.#{name} -> #{self[s].inspect}"
	self[s]
  end
end

Instance Attribute Details

#typemapObject

Returns the value of attribute typemap.



310
311
312
# File 'lib/cmpi.rb', line 310

def typemap
  @typemap
end

Instance Method Details

#eachObject



311
312
313
314
315
# File 'lib/cmpi.rb', line 311

def each
  (0..size-1).each do |i|
	yield self.get_property_at(i)
  end
end

#to_sObject



316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/cmpi.rb', line 316

def to_s
  path = objectpath
  keys = []
  path.each { |val,name| keys << name }
  s = ""
  self.each do |value,name|
	next unless value
	next if keys.include? name
	s << ", " unless s.empty?
	s << "\"#{name}\"=>#{value.inspect}"
  end
  "#{path} #{s}"
end