cim 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/History.txt +19 -0
- data/LICENSE +58 -0
- data/README.rdoc +24 -8
- data/Rakefile +3 -23
- data/cim.gemspec +27 -0
- data/lib/cim.rb +54 -23
- data/lib/cim/association.rb +27 -1
- data/lib/cim/class.rb +51 -8
- data/lib/cim/class_feature.rb +40 -11
- data/lib/cim/indication.rb +14 -0
- data/lib/cim/instance.rb +18 -2
- data/lib/cim/method.rb +28 -1
- data/lib/cim/named_element.rb +55 -7
- data/lib/cim/property.rb +27 -5
- data/lib/cim/qualifier.rb +47 -2
- data/lib/cim/qualifier_declaration.rb +59 -13
- data/lib/cim/qualifier_flavors.rb +84 -10
- data/lib/cim/qualifier_scopes.rb +87 -0
- data/lib/cim/qualifier_set.rb +73 -0
- data/lib/cim/reference.rb +18 -0
- data/lib/cim/type.rb +82 -1
- data/lib/cim/variant.rb +39 -0
- data/tasks/clean.rake +9 -0
- data/tasks/doc.rake +14 -0
- data/tasks/test.rake +6 -0
- data/test/test_method.rb +2 -1
- data/test/test_qualifier_set.rb +39 -0
- metadata +37 -67
- data/Manifest.txt +0 -27
- data/lib/cim/qualifier_scope.rb +0 -37
- data/lib/cim/qualifiers.rb +0 -53
data/lib/cim/indication.rb
CHANGED
@@ -1,6 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# cim/indication.rb - class CIM::Indication
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# Indication is a Class whose Instances are sending asynchronous notifications
|
13
|
+
#
|
2
14
|
class Indication < Class
|
15
|
+
#
|
3
16
|
# true if class has indications (indication provider)
|
17
|
+
#
|
4
18
|
def indication?
|
5
19
|
true
|
6
20
|
end
|
data/lib/cim/instance.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#
|
2
|
+
# cim/instance.rb - class CIM::Instance
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
10
|
+
module CIM
|
11
|
+
#
|
12
|
+
# Instance represents a static Class object (defined in a MOF file)
|
13
|
+
#
|
14
|
+
# --
|
15
|
+
# - to be implemented
|
16
|
+
#
|
17
|
+
class Instance < Class
|
18
|
+
end
|
3
19
|
end
|
data/lib/cim/method.rb
CHANGED
@@ -1,15 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# cim/method.rb - class CIM::Method
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# A Method defines a function member of a Class.
|
13
|
+
#
|
14
|
+
# For data members, see Property.
|
15
|
+
#
|
2
16
|
class Method < CIM::ClassFeature
|
3
17
|
attr_reader :parameters
|
18
|
+
#
|
19
|
+
# Create a Method with return type (Type) and name (String), optional Qualifiers and parameters (Property)
|
20
|
+
#
|
21
|
+
# call-seq:
|
22
|
+
# Method.new(:bool, "do_something")
|
23
|
+
# Method.new(:bool, "do_something", qualifiers)
|
24
|
+
# Method.new(:bool, "do_something", qualifiers, parameters)
|
25
|
+
#
|
4
26
|
def initialize type, name, qualifiers = nil, parameters = nil
|
5
27
|
parameters = nil if parameters.kind_of?(::Enumerable) && parameters.empty?
|
6
28
|
@parameters = parameters
|
7
|
-
qualifiers = [ qualifiers ] unless qualifiers.kind_of?(Enumerable)
|
8
29
|
super type,name,qualifiers
|
9
30
|
end
|
31
|
+
#
|
32
|
+
# Makes a Method recognizable in the set of Class features.
|
33
|
+
#
|
10
34
|
def method?
|
11
35
|
true
|
12
36
|
end
|
37
|
+
#
|
38
|
+
# returns a string representation in MOF syntax format
|
39
|
+
#
|
13
40
|
def to_s
|
14
41
|
p = @parameters.join(", ") if @parameters
|
15
42
|
"#{super}(#{p})"
|
data/lib/cim/named_element.rb
CHANGED
@@ -1,17 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# cim/named_element.rb - class CIM::NamedElement
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# The NamedElement is a basic building block for the CIM schema, acting as a base class
|
13
|
+
# for Class and Property
|
14
|
+
#
|
15
|
+
# A NamedElement has a name (String) and qualifiers (Qualifiers)
|
16
|
+
#
|
2
17
|
class NamedElement
|
3
|
-
attr_reader :name, :
|
4
|
-
|
18
|
+
attr_reader :name, :qualifiers
|
19
|
+
#
|
20
|
+
# Create a NamedElement with a name and qualifiers
|
21
|
+
#
|
22
|
+
def initialize name, qualifiers = nil
|
5
23
|
raise "NamedElement must have a name" unless name
|
6
24
|
@name = name.to_s
|
7
|
-
|
25
|
+
unless qualifiers.nil?
|
26
|
+
unless qualifiers.is_a?(QualifierSet)
|
27
|
+
if qualifiers.kind_of?(::Enumerable) && qualifiers.empty?
|
28
|
+
qualifiers = nil
|
29
|
+
else
|
30
|
+
qualifiers = QualifierSet.new qualifiers
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@qualifiers = qualifiers
|
8
35
|
end
|
36
|
+
#
|
37
|
+
# Add a Qualifier to the NamedElements qualifiers
|
38
|
+
#
|
9
39
|
def << qualifier
|
10
|
-
@
|
40
|
+
@qualifiers << (normalize qualifier)
|
11
41
|
end
|
12
|
-
|
13
|
-
|
42
|
+
#
|
43
|
+
# Check if a Qualifier is included
|
44
|
+
#
|
45
|
+
def include? qualifier
|
46
|
+
@qualifiers.include?(normalize qualifier)
|
47
|
+
end
|
48
|
+
alias includes? include?
|
49
|
+
#
|
50
|
+
# Returns a string representation of the NamedElement
|
51
|
+
#
|
52
|
+
def to_s
|
53
|
+
s = ""
|
54
|
+
s << "[#{@qualifiers.join(', ')}]\n " if @qualifiers
|
55
|
+
s << "#{@name}"
|
56
|
+
end
|
57
|
+
private
|
58
|
+
def normalize qualifier
|
59
|
+
unless qualifier.is_a?(CIM::Qualifier)
|
60
|
+
qualifier = Qualifier.new(qualifier)
|
61
|
+
end
|
62
|
+
qualifier
|
14
63
|
end
|
15
64
|
end
|
16
65
|
end
|
17
|
-
|
data/lib/cim/property.rb
CHANGED
@@ -1,13 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# cim/property.rb - class CIM::Property
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# A Property defines a data member of a Class.
|
13
|
+
#
|
14
|
+
# For method members, see Method.
|
15
|
+
#
|
2
16
|
class Property < CIM::ClassFeature
|
3
17
|
attr_reader :default
|
4
|
-
|
18
|
+
#
|
19
|
+
# Create a Property with type (Type) and name (String), optional QualifierSet and default value
|
20
|
+
#
|
21
|
+
# call-seq:
|
22
|
+
# Property.new(:bool, "flag")
|
23
|
+
# Property.new(:bool, "flag", qualifier_set)
|
24
|
+
# Property.new(:bool, "flag", qualifier_set, true)
|
25
|
+
#
|
26
|
+
def initialize type, name, qualifier_set=nil, default=nil
|
5
27
|
@default = default
|
6
|
-
|
7
|
-
qualifiers = [ qualifiers ]
|
8
|
-
end
|
9
|
-
super type, name, qualifiers
|
28
|
+
super type, name, qualifier_set
|
10
29
|
end
|
30
|
+
#
|
31
|
+
# Makes a Property recognizable in the set of Class features.
|
32
|
+
#
|
11
33
|
def property?
|
12
34
|
true
|
13
35
|
end
|
data/lib/cim/qualifier.rb
CHANGED
@@ -1,12 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# cim/qualifier.rb - class CIM::Qualifier
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# A Qualifier is a modifier containing information to describe a Class, an Instance,
|
13
|
+
# a Property, a Method or a parameter.
|
14
|
+
#
|
15
|
+
# Qualifier can be seen as an instance of QualifierDeclaration
|
16
|
+
#
|
2
17
|
class Qualifier
|
3
18
|
attr_reader :declaration, :value, :flavor
|
19
|
+
#
|
20
|
+
# call-seq:
|
21
|
+
# Qualifier.new qualifier_declaration
|
22
|
+
# Qualifier.new qualifier_declaration, value
|
23
|
+
# Qualifier.new qualifier_declaration, value, flavor
|
24
|
+
#
|
4
25
|
def initialize declaration, value = nil, flavor = nil
|
5
26
|
raise "Not a CIM::QualifierDeclaration: #{declaration.inspect}" unless declaration.is_a?(CIM::QualifierDeclaration)
|
6
27
|
@declaration = declaration
|
28
|
+
# FIXME, check if the value type matches the declaration type
|
7
29
|
@value = value
|
8
30
|
@flavor = flavor
|
9
31
|
end
|
32
|
+
#
|
33
|
+
# Check for equality against Qualifier, QualifierDeclaration, String, or Symbol
|
34
|
+
#
|
10
35
|
def == q
|
11
36
|
# puts "CIM::Qualifier ->#{self} == #{q.inspect}"
|
12
37
|
case q
|
@@ -16,15 +41,35 @@ module CIM
|
|
16
41
|
(@flavor == q.flavor)
|
17
42
|
when CIM::QualifierDeclaration
|
18
43
|
@declaration == q
|
44
|
+
when String
|
45
|
+
@declaration.name.downcase == q.downcase && @value.nil? && @flavor.nil?
|
19
46
|
when Symbol
|
20
|
-
|
47
|
+
self == q.to_s # recycle
|
21
48
|
else
|
22
49
|
false
|
23
50
|
end
|
24
51
|
end
|
52
|
+
#
|
53
|
+
# Name of qualifier (String)
|
54
|
+
#
|
55
|
+
def name
|
56
|
+
@declaration.name
|
57
|
+
end
|
58
|
+
#
|
59
|
+
# Type of qualifier (Type)
|
60
|
+
#
|
61
|
+
def type
|
62
|
+
@declaration.type
|
63
|
+
end
|
64
|
+
#
|
65
|
+
# Name of qualifier as symbol (Symbol)
|
66
|
+
#
|
25
67
|
def to_sym
|
26
|
-
@declaration.
|
68
|
+
@declaration.to_sym
|
27
69
|
end
|
70
|
+
#
|
71
|
+
# returns a string representation in MOF syntax format
|
72
|
+
#
|
28
73
|
def to_s
|
29
74
|
s = "#{@declaration.name.capitalize}"
|
30
75
|
case @value
|
@@ -1,31 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# cim/qualifier_declaration.rb - class CIM::QualifierDeclaration
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
11
|
+
#
|
12
|
+
# A Qualifier is a modifier containing information to describe a Class, an Instance,
|
13
|
+
# a Property, a Method or a parameter.
|
14
|
+
#
|
15
|
+
# A qualifier needs to be declared before it can be used.
|
16
|
+
#
|
17
|
+
# Typical qualifiers are e.g.
|
18
|
+
# Description:: (string type) to add a textual information about an element of the CIM model.
|
19
|
+
# Counter,Gauge:: to explain how a numeric value is to be interpreted
|
20
|
+
# Deprecated:: to denote end-of-life for model elements
|
21
|
+
# Min, Max:: (MinLen, MaxLen, MinValue, MaxValue) limits
|
22
|
+
#
|
23
|
+
# A QualifierDeclaration declares a qualifier by
|
24
|
+
# name:: (String)
|
25
|
+
# type:: (Type) (defaults to bool)
|
26
|
+
# default value:: (Variant) (defaults to false)
|
27
|
+
# scopes:: (QualifierScopes) (where the qualifier can be used)
|
28
|
+
# flavor:: (QualifierFlavors) (how the qualifier is applied)
|
29
|
+
#
|
30
|
+
#
|
2
31
|
class QualifierDeclaration < NamedElement
|
3
32
|
|
4
|
-
attr_reader :type, :default, :
|
5
|
-
|
6
|
-
|
33
|
+
attr_reader :type, :default, :scopes, :flavors
|
34
|
+
#
|
35
|
+
# Create a new QualifierDeclaration
|
36
|
+
#
|
37
|
+
def initialize name, type = :bool, default = false, scopes = nil, flavors = nil
|
7
38
|
@type = (type.kind_of? Type) ? type : Type.new(type)
|
8
39
|
@default = (default.nil? || default.is_a?(CIM::Variant)) ? default : CIM::Variant.new(@type, default)
|
9
|
-
@
|
10
|
-
@
|
40
|
+
@scopes = scopes
|
41
|
+
@flavors = flavors
|
11
42
|
super name
|
12
43
|
end
|
13
|
-
|
44
|
+
#
|
45
|
+
# Test for equality by comparing name and type
|
46
|
+
#
|
14
47
|
def == q
|
15
|
-
|
16
|
-
|
17
|
-
|
48
|
+
# puts "QualifierDeclaration(#{@name}:#{@type}) == #{q.class}(#{q})"
|
49
|
+
case q
|
50
|
+
when QualifierDeclaration
|
51
|
+
(@name.downcase == q.name.downcase) &&
|
52
|
+
(@type.nil? || q.type.nil? || (@type == q.type))
|
53
|
+
when String
|
54
|
+
@name.downcase == q.downcase
|
55
|
+
when Symbol
|
56
|
+
@name.downcase == q.to_s.downcase
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
18
60
|
end
|
19
|
-
|
61
|
+
#
|
62
|
+
# return a Symbol representation of the qualifier name
|
63
|
+
#
|
20
64
|
def to_sym
|
21
65
|
@name.downcase.to_sym
|
22
66
|
end
|
23
|
-
|
67
|
+
#
|
68
|
+
# returns a String representation in MOF syntax format
|
69
|
+
#
|
24
70
|
def to_s
|
25
71
|
s = "Qualifier #{@name} : #{@type}"
|
26
72
|
s << " = #{@default}" if @default
|
27
|
-
s << ",\n\t#{@
|
28
|
-
s << ",\n\t#{@
|
73
|
+
s << ",\n\t#{@scopes}" if @scopes
|
74
|
+
s << ",\n\t#{@flavors}" if @flavors
|
29
75
|
s
|
30
76
|
end
|
31
77
|
end
|
@@ -1,5 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# cim/qualifier_flavor.rb - class CIM::QualifierFlavors, class CIM::QualifierFlavorError
|
3
|
+
#
|
4
|
+
# A pure-Ruby implementation of the CIM meta model.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
|
7
|
+
#
|
8
|
+
# Licensed under the Ruby license
|
9
|
+
#
|
1
10
|
module CIM
|
2
|
-
|
11
|
+
#
|
12
|
+
# QualifierFlavorError is raised during QualifierFlavors creation
|
13
|
+
#
|
3
14
|
class QualifierFlavorError < ArgumentError
|
4
15
|
def initialize flavor
|
5
16
|
@flavor = flavor
|
@@ -8,26 +19,89 @@ module CIM
|
|
8
19
|
"#{@flavor} is not a valid qualifier flavor"
|
9
20
|
end
|
10
21
|
end
|
11
|
-
|
22
|
+
#
|
23
|
+
# Qualifier flavors are a fixed set. QualifierFlavors tracks which flavors are enabled for a specific QualifierDeclaration.
|
24
|
+
#
|
25
|
+
# Allowed flavors are
|
26
|
+
#
|
27
|
+
# amended:: [wmi] Marks a qualifier value for localization (default: false)
|
28
|
+
# enableoverride:: The qualifier can be overriden (in a subclass) (default: true)
|
29
|
+
# disableoverride:: The qualifier can not be overriden (default: false)
|
30
|
+
# restricted:: The qualifier only applies to the class in which it is declared (default: false)
|
31
|
+
# toinstance:: [wmi]
|
32
|
+
# tosubclass:: The qualifier is inherited by any subclass (default: true)
|
33
|
+
# translatable:: Marks a qualifier value for localization (default: false)
|
34
|
+
#
|
12
35
|
class QualifierFlavors
|
13
36
|
FLAVORS = [:amended, :enableoverride, :disableoverride, :restricted, :toinstance, :tosubclass, :translatable]
|
14
37
|
attr_reader :flavors
|
15
|
-
|
38
|
+
#
|
39
|
+
# Create QualifierFlavors with an initial flavor. More flavors can be added through the << method.
|
40
|
+
#
|
41
|
+
# call-seq:
|
42
|
+
# QualifierFlavors.new :tosubclass => qualifier_flavors
|
43
|
+
# QualifierFlavors.new "tosubclass" => qualifier_flavors
|
44
|
+
# QualifierFlavors.new "ToSubClass" => qualifier_flavors
|
45
|
+
#
|
46
|
+
# The flavor can be named as a string or a symbol.
|
47
|
+
#
|
48
|
+
def initialize *flavors
|
16
49
|
@flavors = []
|
17
|
-
|
50
|
+
flavors.flatten.each do |flavor|
|
51
|
+
self << flavor
|
52
|
+
end
|
18
53
|
end
|
54
|
+
#
|
55
|
+
# Add a flavor to the set
|
56
|
+
# The flavor can be named as a string or a symbol.
|
57
|
+
#
|
58
|
+
# call-seq:
|
59
|
+
# qualifier_flavors << :tosubclass
|
60
|
+
# qualifier_flavors << "tosubclass"
|
61
|
+
# qualifier_flavors << "ToSubClass"
|
62
|
+
#
|
63
|
+
# Raises QualifierFlavorError if its not an allowed flavor
|
64
|
+
#
|
19
65
|
def << flavor
|
20
|
-
|
21
|
-
f = flavor.to_sym
|
22
|
-
raise QualifierFlavorError.new("#{flavor}") unless FLAVORS.include? f
|
23
|
-
@flavors << f
|
66
|
+
@flavors << normalize(flavor)
|
24
67
|
self
|
25
68
|
end
|
26
|
-
|
27
|
-
|
69
|
+
#
|
70
|
+
# Number of flavors in the set
|
71
|
+
#
|
72
|
+
def size
|
73
|
+
@flavors.size
|
74
|
+
end
|
75
|
+
#
|
76
|
+
# Check if a specific flavor is included in the set
|
77
|
+
#
|
78
|
+
# call-seq:
|
79
|
+
# qualifier_flavors.include? :tosubclass
|
80
|
+
# qualifier_flavors.include? "tosubclass"
|
81
|
+
# qualifier_flavors.include? "ToSubClass"
|
82
|
+
#
|
83
|
+
# Raises QualifierFlavorError if its not an allowed flavor
|
84
|
+
#
|
85
|
+
def include? flavor
|
86
|
+
@flavors.include?(normalize flavor)
|
28
87
|
end
|
88
|
+
alias includes? include?
|
89
|
+
#
|
90
|
+
# returns a string representation in MOF syntax format
|
91
|
+
#
|
29
92
|
def to_s
|
30
93
|
"Flavor(#{@flavors.join(', ')})"
|
31
94
|
end
|
95
|
+
private
|
96
|
+
#
|
97
|
+
# Normalize a flavor passed as string or symbol
|
98
|
+
# Raises QualifierFlavorError if its not an allowed flavor
|
99
|
+
#
|
100
|
+
def normalize flavor
|
101
|
+
flavor.downcase! if flavor.kind_of? String
|
102
|
+
f = flavor.to_sym
|
103
|
+
raise QualifierFlavorError.new("#{flavor}") unless FLAVORS.include? f
|
104
|
+
f
|
105
|
+
end
|
32
106
|
end
|
33
107
|
end
|