class Cmpi::CMPIInstance

CMPIInstance

Attributes

typemap[RW]

Public Instance Methods

each() { |get_property_at| ... } click to toggle source
# File ruby/cmpi.rb, line 362
def each
  (0..size-1).each do |i|
    yield self.get_property_at(i)
  end
end
method_missing(name, *args) click to toggle source

Allow Instance.Property and Instance.Property=

# File ruby/cmpi.rb, line 388
    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 RCErrInvalidClass.new(CMPI_RC_ERR_INVALID_CLASS, "Cmpi::#{self.objectpath.classname}.typemap not defined")
          end
        end
        t = @typemap[n]
        raise RCErrNotFound.new(CMPI_RC_ERR_NOT_FOUND, "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
to_s() click to toggle source
# File ruby/cmpi.rb, line 367
def to_s
  # objectpath only covers the key properties
  path = objectpath
  keys = []
  path.each { |val,name| keys << name }
  # now iterate over the instance properties, filter
  # out the key properties from the objectpath
  # and collect the non-key properties
  s = ""
  self.each do |value,name|
    next unless value
    next if keys.include? name
    s << ", " unless s.empty?
    s << "\"#{name}\"=#{value.inspect}"
  end
  # path has the key properties, s has the non-key properties
  "#{path} #{s}"
end