Parent

Class/Module Index [+]

Quicksearch

CIMI::Model::Base

Attributes

attribute_values[R]

We keep the values of the attributes in a hash

Public Class Methods

act_as_root_entity(name=nil) click to toggle source
# File lib/cimi/model/base.rb, line 202
def self.act_as_root_entity(name=nil)
  if name
    name = name.to_s.camelize.pluralize
  else
    name = xml_tag_name.pluralize.uncapitalize
  end
  CIMI::Model.register_as_root_entity! name
end
add_attributes!(names, attr_klass, &block) click to toggle source
# File lib/cimi/model/base.rb, line 120
def add_attributes!(names, attr_klass, &block)
  if self.respond_to? :schema
    schema.add_attributes!(names, attr_klass, &block)
  else
    base_schema.add_attributes!(names, attr_klass, &block)
  end
  names.each do |name|
    define_method(name) { @attribute_values[name] }
    define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }
  end
end
all(_self) click to toggle source
# File lib/cimi/model/base.rb, line 211
def self.all(_self); find(:all, _self); end
base_schema() click to toggle source
# File lib/cimi/model/base.rb, line 97
def base_schema
  @schema ||= CIMI::Model::Schema.new
end
base_schema_cloned?() click to toggle source
# File lib/cimi/model/base.rb, line 106
def base_schema_cloned?
  @schema_duped
end
clone_base_schema() click to toggle source
# File lib/cimi/model/base.rb, line 101
def clone_base_schema
  @schema_duped = true
  @schema = Marshal::load(Marshal.dump(superclass.base_schema))
end
from_json(text) click to toggle source

Construct a new object

# File lib/cimi/model/base.rb, line 159
def self.from_json(text)
  json = JSON::parse(text)
  model = self.new
  @schema.from_json(json, model)
  model
end
from_xml(text) click to toggle source

Construct a new object from the XML representation xml

# File lib/cimi/model/base.rb, line 151
def self.from_xml(text)
  xml = XmlSimple.xml_in(text, :force_content => true)
  model = self.new
  @schema.from_xml(xml, model)
  model
end
inherited(child) click to toggle source
# File lib/cimi/model/base.rb, line 112
def inherited(child)
  child.instance_eval do
    def schema
      base_schema_cloned? ? @schema : clone_base_schema
    end
  end
end
new(values = {}) click to toggle source

Factory methods

# File lib/cimi/model/base.rb, line 146
def initialize(values = {})
  @attribute_values = values
end
schema() click to toggle source
# File lib/cimi/model/base.rb, line 114
def schema
  base_schema_cloned? ? @schema : clone_base_schema
end
to_json(model) click to toggle source
# File lib/cimi/model/base.rb, line 174
def self.to_json(model)
  JSON::unparse(@schema.to_json(model))
end
to_xml(model) click to toggle source
# File lib/cimi/model/base.rb, line 178
def self.to_xml(model)
  xml = @schema.to_xml(model)
  xml["xmlns"] = "http://www.dmtf.org/cimi"
  XmlSimple.xml_out(xml, :root_name => xml_tag_name)
end
xml_tag_name() click to toggle source

Serialize

# File lib/cimi/model/base.rb, line 170
def self.xml_tag_name
  self.name.split("::").last
end

Public Instance Methods

[](a) click to toggle source
# File lib/cimi/model/base.rb, line 135
def [](a)
  @attribute_values[a]
end
[]=(a, v) click to toggle source
# File lib/cimi/model/base.rb, line 139
def []=(a, v)
  @attribute_values[a] = v
end
filter_by(filter_opts) click to toggle source
# File lib/cimi/model/base.rb, line 213
def filter_by(filter_opts)
  return self if filter_opts.nil?
  return filter_attributes(filter_opts.split(',').map{ |a| a.intern }) if filter_opts.include? ','
  case filter_opts
    when /^([\w\_]+)$/ then filter_attributes([$1.intern])
    when /^([\w\_]+)\[(\d+\-\d+)\]$/ then filter_by_arr_range($1.intern, $2)
    when /^([\w\_]+)\[(\d+)\]$/ then filter_by_arr_index($1.intern, $2)
    else self
  end
end
to_json() click to toggle source
# File lib/cimi/model/base.rb, line 184
def to_json
  self.class.to_json(self)
end
to_xml() click to toggle source
# File lib/cimi/model/base.rb, line 188
def to_xml
  self.class.to_xml(self)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.