Class/Module Index [+]

Quicksearch

CIMI::Model

The base class for any CIMI object that we either read from a request or write as a response. This class handles serializing/deserializing XML and JSON into a common form.

Defining the schema

The conversion of XML and JSON into internal objects is based on a schema that is defined through a DSL:

class Machine < CIMI::Model::Base
  text :status
  href :meter
  array :volumes do
    scalar :href, :attachment_point, :protocol
  end
end

The DSL automatically takes care of converting identifiers from their underscored form to the camel-cased form used by CIMI. The above class can be used in the following way:

machine = Machine.from_xml(some_xml)
if machine.status == "UP"
  ...
end
sda = machine.volumes.find { |v| v.attachment_point == "/dev/sda" }
handle_meter(machine.meter.href)

The keywords for the DSL are

[scalar(names, ...)]
  Define a scalar attribute; in JSON, this is represented as a string
  property. In XML, this can be represented in a number of ways,
  depending on whether the option :text is set:
    * :text not set: attribute on the enclosing element
    * :text == :direct: the text content of the enclosing element
    * :text == :nested: the text content of an element +<name>...</name>+
[text(names)]
  A shorthand for +scalar(names, :text => :nested)+, i.e., for
  attributes that in XML are represented by their own tags
[href(name)]
  A shorthand for +struct name { scalar :href }+; in JSON, this is
  represented as +{ name: { "href": string } }+, and in XML as +<name
  href="..."/>+
[struct(name, opts, &block)]
  A structured subobject; the block defines the schema of the
  subobject. The +:content+ option can be used to specify the attribute
  that should receive the content of hte corresponding XML element
[array(name, opts, &block)]
  An array of structured subobjects; the block defines the schema of
  the subobjects.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Public Class Methods

register_as_root_entity!(name) click to toggle source
# File lib/cimi/model/base.rb, line 72
def self.register_as_root_entity!(name)
  @root_entities ||= []
  @root_entities << name
  unless CIMI::Model::CloudEntryPoint.href_defined?(name)
    CIMI::Model::CloudEntryPoint.send(:href, name.underscore)
  end
end
root_entities() click to toggle source
# File lib/cimi/model/base.rb, line 80
def self.root_entities
  @root_entities || []
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.