cim 0.5.0 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,16 @@
1
+ === 1.3 2011-11-16
2
+
3
+ * Make QualifierScope and QualifierFlavor Array
4
+ (remove :elements and :flavors accessors)
5
+
6
+ * Rename CIM::QualifierScopesError to CIM::QualifierScopeError
7
+
8
+ === 1.2.1 2011-11-08
9
+
10
+ * Ruby 1.9 support
11
+
12
+ === 1.2.0
13
+
1
14
  === 0.5.0 2011-09-29
2
15
 
3
16
  * Clean up Rakefile, support Bundler
@@ -18,6 +18,9 @@ http://www.dmtf.org/education/mof for details}
18
18
 
19
19
  s.rubyforge_project = "cim"
20
20
 
21
+ s.add_development_dependency('rake')
22
+ s.add_development_dependency('bundler')
23
+
21
24
  s.files = `git ls-files`.split("\n")
22
25
  s.files.reject! { |fn| fn == '.gitignore' }
23
26
  s.extra_rdoc_files = Dir['README*', 'TODO*', 'CHANGELOG*', 'LICENSE']
data/lib/cim.rb CHANGED
@@ -41,7 +41,7 @@ $:.unshift(File.dirname(__FILE__)) unless
41
41
  #
42
42
 
43
43
  module CIM
44
- VERSION = '0.5.0'
44
+ VERSION = '1.3'
45
45
  require 'cim/type'
46
46
  require 'cim/variant'
47
47
  require 'cim/qualifier_flavors'
@@ -55,6 +55,4 @@ module CIM
55
55
  require 'cim/reference'
56
56
  require 'cim/method'
57
57
  require 'cim/class'
58
- require 'cim/association'
59
- require 'cim/indication'
60
58
  end
@@ -18,7 +18,7 @@ module CIM
18
18
  # and contain features (properties or methods).
19
19
  #
20
20
  class Class < CIM::NamedElement
21
- attr_reader :alias_name, :superclass, :features
21
+ attr_reader :alias_name, :superclass
22
22
  #
23
23
  # Creates a new Class with name (String), qualifiers, alias, superclass and features
24
24
  #
@@ -30,6 +30,23 @@ module CIM
30
30
  # Class.new("MyClass", qualifiers, "my_class")
31
31
  # Class.new("MyClass", qualifiers, "my_class", "SuperClass")
32
32
  # Class.new("MyClass", qualifiers, "my_class", "SuperClass", features)
33
+ # if qualifiers and qualifiers.include?(:association, :boolean)
34
+ # FIXME: 'association' must be first
35
+ # Context:
36
+ #
37
+ # The remaining qualifier list must not include
38
+ # the ASSOCIATION qualifier again. If the
39
+ # association has no super association, then at
40
+ # least two references must be specified! The
41
+ # ASSOCIATION qualifier may be omitted in
42
+ # sub associations.
43
+ # result = CIM::Association.new(val[2],qualifiers,val[3],val[4],features)
44
+ # elsif qualifiers and qualifiers.include?(:indication, :boolean)
45
+ # FIXME: 'indication' must be first
46
+ # FIXME: features must not include references
47
+ # result = CIM::Indication.new(val[2],qualifiers,val[3],val[4],features)
48
+ # else
49
+
33
50
  #
34
51
  def initialize name, qualifiers = nil, alias_name = nil, superclass = nil, features = nil
35
52
  @alias_name = alias_name
@@ -39,11 +56,22 @@ module CIM
39
56
  # puts "CIM::Class.new(#{@features})"
40
57
  super name, qualifiers
41
58
  end
59
+
60
+ def method_missing name, *args
61
+ @qualifiers[name]
62
+ end
63
+
64
+ #
65
+ # Ensure features can be enumerated
66
+ #
67
+ def features
68
+ @features || []
69
+ end
42
70
  #
43
71
  # Iterate over features flagged as keys
44
72
  #
45
73
  def each_key
46
- @features.each do |f|
74
+ features.each do |f|
47
75
  yield f if f.key?
48
76
  end
49
77
  end
@@ -51,16 +79,19 @@ module CIM
51
79
  # true if class has instances (instance provider)
52
80
  #
53
81
  def instance?
54
- @features.size > 0
82
+ features.each do |f|
83
+ next if f.reference?
84
+ next if f.method?
85
+ return true if f.property?
86
+ end
87
+ false
55
88
  end
56
89
  #
57
90
  # true if class has methods (method provider)
58
91
  #
59
92
  def method?
60
- @features.each do |f|
61
- case f
62
- when CIM::Method: return true
63
- end
93
+ features.each do |f|
94
+ return true if f.method?
64
95
  end
65
96
  false
66
97
  end
@@ -68,13 +99,13 @@ module CIM
68
99
  # true if class has associations (association provider)
69
100
  #
70
101
  def association?
71
- false
102
+ include? :association
72
103
  end
73
104
  #
74
105
  # true if class has indications (indication provider)
75
106
  #
76
107
  def indication?
77
- false
108
+ include? :indication
78
109
  end
79
110
  #
80
111
  # returns a string representation in MOF syntax format
@@ -22,7 +22,7 @@ module CIM
22
22
  # if has key qualifier
23
23
  #
24
24
  def key?
25
- @qualifiers && @qualifiers.include?(:key,:bool)
25
+ @qualifiers && @qualifiers.include?(:key,:boolean)
26
26
  end
27
27
  #
28
28
  # if static (class-level) feature
@@ -51,7 +51,7 @@ module CIM
51
51
  protected
52
52
  def initialize type, name, qualifiers = nil
53
53
  # :notnew:
54
- @type = (type.is_a? CIM::Type) ? type : CIM::Type.new(type)
54
+ @type = CIM::Type.normalize type
55
55
  super name, qualifiers
56
56
  end
57
57
  #
@@ -14,21 +14,25 @@ module CIM
14
14
  # For data members, see Property.
15
15
  #
16
16
  class Method < CIM::ClassFeature
17
- attr_reader :parameters
18
17
  #
19
18
  # Create a Method with return type (Type) and name (String), optional Qualifiers and parameters (Property)
20
19
  #
21
20
  # call-seq:
22
- # Method.new(:bool, "do_something")
23
- # Method.new(:bool, "do_something", qualifiers)
24
- # Method.new(:bool, "do_something", qualifiers, parameters)
21
+ # Method.new(:boolean, "do_something")
22
+ # Method.new(:boolean, "do_something", qualifiers)
23
+ # Method.new(:boolean, "do_something", qualifiers, parameters)
25
24
  #
26
25
  def initialize type, name, qualifiers = nil, parameters = nil
27
- parameters = nil if parameters.kind_of?(::Enumerable) && parameters.empty?
28
26
  @parameters = parameters
29
27
  super type,name,qualifiers
30
28
  end
31
29
  #
30
+ # parameters accessor
31
+ #
32
+ def parameters
33
+ @parameters || []
34
+ end
35
+ #
32
36
  # Makes a Method recognizable in the set of Class features.
33
37
  #
34
38
  def method?
@@ -38,7 +42,7 @@ module CIM
38
42
  # returns a string representation in MOF syntax format
39
43
  #
40
44
  def to_s
41
- p = @parameters.join(", ") if @parameters
45
+ p = parameters.join(", ")
42
46
  "#{super}(#{p})"
43
47
  end
44
48
  end
@@ -7,6 +7,7 @@
7
7
  #
8
8
  # Licensed under the Ruby license
9
9
  #
10
+
10
11
  module CIM
11
12
  #
12
13
  # The NamedElement is a basic building block for the CIM schema, acting as a base class
@@ -22,28 +23,19 @@ module CIM
22
23
  def initialize name, qualifiers = nil
23
24
  raise "NamedElement must have a name" unless name
24
25
  @name = name.to_s
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
26
+ @qualifiers = (qualifiers) ? CIM::QualifierSet.normalize(qualifiers) : CIM::QualifierSet.new
35
27
  end
36
28
  #
37
29
  # Add a Qualifier to the NamedElements qualifiers
38
30
  #
39
31
  def << qualifier
40
- @qualifiers << (normalize qualifier)
32
+ @qualifiers << CIM::Qualifier.normalize(qualifier)
41
33
  end
42
34
  #
43
35
  # Check if a Qualifier is included
44
36
  #
45
37
  def include? qualifier
46
- @qualifiers.include?(normalize qualifier)
38
+ @qualifiers.include? qualifier
47
39
  end
48
40
  alias includes? include?
49
41
  #
@@ -54,12 +46,5 @@ module CIM
54
46
  s << "[#{@qualifiers.join(', ')}]\n " if @qualifiers
55
47
  s << "#{@name}"
56
48
  end
57
- private
58
- def normalize qualifier
59
- unless qualifier.is_a?(CIM::Qualifier)
60
- qualifier = Qualifier.new(qualifier)
61
- end
62
- qualifier
63
- end
64
49
  end
65
50
  end
@@ -19,9 +19,9 @@ module CIM
19
19
  # Create a Property with type (Type) and name (String), optional QualifierSet and default value
20
20
  #
21
21
  # call-seq:
22
- # Property.new(:bool, "flag")
23
- # Property.new(:bool, "flag", qualifier_set)
24
- # Property.new(:bool, "flag", qualifier_set, true)
22
+ # Property.new(:boolean, "flag")
23
+ # Property.new(:boolean, "flag", qualifier_set)
24
+ # Property.new(:boolean, "flag", qualifier_set, true)
25
25
  #
26
26
  def initialize type, name, qualifier_set=nil, default=nil
27
27
  @default = default
@@ -15,6 +15,10 @@ module CIM
15
15
  # Qualifier can be seen as an instance of QualifierDeclaration
16
16
  #
17
17
  class Qualifier
18
+ def self.normalize type
19
+ (type.is_a? self) ? type : self.new(type)
20
+ end
21
+
18
22
  attr_reader :declaration, :value, :flavor
19
23
  #
20
24
  # call-seq:
@@ -73,8 +77,8 @@ module CIM
73
77
  def to_s
74
78
  s = "#{@declaration.name.capitalize}"
75
79
  case @value
76
- when nil:
77
- when Array:
80
+ when nil
81
+ when Array
78
82
  s << " {#{@value.join(', ')}}"
79
83
  else
80
84
  s << "(#{@value.inspect})"
@@ -22,7 +22,7 @@ module CIM
22
22
  #
23
23
  # A QualifierDeclaration declares a qualifier by
24
24
  # name:: (String)
25
- # type:: (Type) (defaults to bool)
25
+ # type:: (Type) (defaults to boolean)
26
26
  # default value:: (Variant) (defaults to false)
27
27
  # scopes:: (QualifierScopes) (where the qualifier can be used)
28
28
  # flavor:: (QualifierFlavors) (how the qualifier is applied)
@@ -34,7 +34,7 @@ module CIM
34
34
  #
35
35
  # Create a new QualifierDeclaration
36
36
  #
37
- def initialize name, type = :bool, default = false, scopes = nil, flavors = nil
37
+ def initialize name, type = :boolean, default = false, scopes = nil, flavors = nil
38
38
  @type = (type.kind_of? Type) ? type : Type.new(type)
39
39
  @default = (default.nil? || default.is_a?(CIM::Variant)) ? default : CIM::Variant.new(@type, default)
40
40
  @scopes = scopes
@@ -32,9 +32,8 @@ module CIM
32
32
  # tosubclass:: The qualifier is inherited by any subclass (default: true)
33
33
  # translatable:: Marks a qualifier value for localization (default: false)
34
34
  #
35
- class QualifierFlavors
35
+ class QualifierFlavors < ::Array
36
36
  FLAVORS = [:amended, :enableoverride, :disableoverride, :restricted, :toinstance, :tosubclass, :translatable]
37
- attr_reader :flavors
38
37
  #
39
38
  # Create QualifierFlavors with an initial flavor. More flavors can be added through the << method.
40
39
  #
@@ -46,7 +45,6 @@ module CIM
46
45
  # The flavor can be named as a string or a symbol.
47
46
  #
48
47
  def initialize *flavors
49
- @flavors = []
50
48
  flavors.flatten.each do |flavor|
51
49
  self << flavor
52
50
  end
@@ -63,16 +61,10 @@ module CIM
63
61
  # Raises QualifierFlavorError if its not an allowed flavor
64
62
  #
65
63
  def << flavor
66
- @flavors << normalize(flavor)
64
+ super(normalize flavor)
67
65
  self
68
66
  end
69
67
  #
70
- # Number of flavors in the set
71
- #
72
- def size
73
- @flavors.size
74
- end
75
- #
76
68
  # Check if a specific flavor is included in the set
77
69
  #
78
70
  # call-seq:
@@ -83,14 +75,14 @@ module CIM
83
75
  # Raises QualifierFlavorError if its not an allowed flavor
84
76
  #
85
77
  def include? flavor
86
- @flavors.include?(normalize flavor)
78
+ super(normalize flavor)
87
79
  end
88
80
  alias includes? include?
89
81
  #
90
82
  # returns a string representation in MOF syntax format
91
83
  #
92
84
  def to_s
93
- "Flavor(#{@flavors.join(', ')})"
85
+ "Flavor(#{self.join(', ')})"
94
86
  end
95
87
  private
96
88
  #
@@ -9,7 +9,7 @@
9
9
  #
10
10
  module CIM
11
11
 
12
- class QualifierScopesError < ArgumentError
12
+ class QualifierScopeError < ArgumentError
13
13
  #
14
14
  # Raised if wrong Scope passed
15
15
  #
@@ -22,9 +22,8 @@ module CIM
22
22
  end
23
23
  end
24
24
 
25
- class QualifierScopes
25
+ class QualifierScopes < ::Array
26
26
  META_ELEMENTS = [ :schema, :class, :association, :indication, :qualifier, :property, :reference, :method, :parameter, :any ]
27
- attr_reader :elements
28
27
  #
29
28
  # call-seq:
30
29
  # QualifierScopes.new => qualifier_scopes
@@ -35,7 +34,6 @@ module CIM
35
34
  # raises QualifierScopesError
36
35
  #
37
36
  def initialize *elements
38
- @elements = []
39
37
  elements.flatten.each do |element|
40
38
  self << element
41
39
  end
@@ -49,7 +47,7 @@ module CIM
49
47
  # raises QualifierScopesError
50
48
  #
51
49
  def << element
52
- @elements << (normalize element)
50
+ self.push(normalize element)
53
51
  self
54
52
  end
55
53
  #
@@ -61,26 +59,21 @@ module CIM
61
59
  # raises QualifierScopesError
62
60
  #
63
61
  def include? element
64
- @elements.include?(normalize element)
62
+ super(normalize element)
65
63
  end
66
64
  alias includes? include?
67
- #
68
- # Number of scopes
69
- #
70
- def size
71
- @elements.size
72
- end
65
+
73
66
  #
74
67
  # returns a string representation in MOF syntax format
75
68
  #
76
69
  def to_s
77
- "Scope(#{@elements.join(', ')})"
70
+ "Scope(#{self.join(', ')})"
78
71
  end
79
72
  private
80
73
  def normalize element
81
74
  element.downcase! if element.is_a?(String)
82
75
  e = element.to_sym
83
- raise QualifierScopesError.new(element) unless META_ELEMENTS.include?(e)
76
+ raise QualifierScopeError.new(element) unless META_ELEMENTS.include?(e)
84
77
  e
85
78
  end
86
79
  end
@@ -12,17 +12,24 @@ module CIM
12
12
  # Set of Qualifier
13
13
  #
14
14
  class QualifierSet < ::Array
15
+ def self.normalize type
16
+ (type.is_a? self) ? type : self.new(type)
17
+ end
18
+
19
+
15
20
  def initialize *args
16
21
  super 0
17
22
  args.flatten.each do |q|
18
23
  case q
19
- when QualifierDeclaration: q = Qualifier.new q
20
- when Qualifier:
24
+ when QualifierDeclaration
25
+ q = Qualifier.new q
26
+ when Qualifier
27
+ # nothing
21
28
  else
22
29
  q = Qualifier.new(QualifierDeclaration.new q)
23
30
  end
24
31
  self << q
25
- end
32
+ end if args
26
33
  end
27
34
  #
28
35
  # check if qualifier exists
@@ -51,9 +58,7 @@ module CIM
51
58
  q == qualifier.declaration
52
59
  when CIM::QualifierDeclaration
53
60
  q == qualifier
54
- when String
55
- q.declaration == qualifier
56
- when Symbol
61
+ when String, Symbol
57
62
  q.declaration == qualifier
58
63
  else
59
64
  raise "Unknown parameter in #{self.class}[]"
@@ -23,22 +23,29 @@ module CIM
23
23
  # uint64:: Unsigned 64-bit integer
24
24
  # sint64:: Signed 64-bit integer
25
25
  # string:: UCS-2 string
26
- # bool:: Boolean
26
+ # boolean:: Boolean
27
27
  # real32:: IEEE 4-byte floating-point
28
28
  # real64:: IEEE 8-byte floating-point
29
- # datetime:: A string containing a date-time
29
+ # dateTime:: A string containing a date-time
30
30
  # reference:: Strongly typed reference
31
31
  # char16:: 16-bit UCS-2 character
32
- # datetime:: Timestamp
33
32
  # void:: -- allowed for WMI only
34
33
  #
35
34
  #
36
35
  class Type
37
- TYPES = [:null,:void,:bool,:char16,:string,:uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64,:real32,:real64,:datetime,:class,:reference,:array]
36
+ def self.normalize type
37
+ (type.is_a? self) ? type : self.new(type)
38
+ end
39
+
40
+ TYPES = [:null,:void,:boolean,:char16,:string,:uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64,:real32,:real64,:dateTime,:class,:reference,:array]
41
+ NORMALIZE = {
42
+ :bool => :boolean,
43
+ :datetime => :dateTime
44
+ }
38
45
  MATCHES = {
39
46
  :null => [],
40
47
  :void => [], # WMI
41
- :bool => [],
48
+ :boolean => [],
42
49
  :char16 => [ :null, :string ],
43
50
  :string => [ :null ],
44
51
  :uint8 => [ :null ],
@@ -51,7 +58,7 @@ module CIM
51
58
  :sint64 => [ :null, :sint8, :sint16, :sint32 ],
52
59
  :real32 => [ :null ],
53
60
  :real64 => [ :null, :real32 ],
54
- :datetime => [ :null ],
61
+ :dateTime => [ :null ],
55
62
  :class => [ :null ],
56
63
  :reference => [ :null ],
57
64
  :array => [ :null ]
@@ -60,13 +67,17 @@ module CIM
60
67
  #
61
68
  # Basic types are created by-symbol or by-name
62
69
  #
63
- # CIM::Type.new(:bool) == CIM::Type.new("bool")
70
+ # CIM::Type.new(:boolean) == CIM::Type.new("boolean")
64
71
  #
65
72
  def initialize type
66
73
  type.downcase! if type.is_a? String
67
74
  @type = type.to_sym
75
+ @type = NORMALIZE[@type] || @type
68
76
  raise TypeError.new("#{type}") unless TYPES.include? @type
69
77
  end
78
+ def array?
79
+ false
80
+ end
70
81
  #
71
82
  # returns a string representation in MOF syntax format
72
83
  #
@@ -84,38 +95,49 @@ module CIM
84
95
  #
85
96
  def == t
86
97
  case t
87
- when Type: t.type == @type
88
- when Symbol: t == @type
89
- when String: t.downcase == @type.to_s
98
+ when Type then t.type == @type
99
+ when Symbol then t == @type
100
+ when String then t.downcase == @type.to_s
90
101
  else
91
102
  false
92
103
  end
93
104
  end
94
105
  private
95
106
  def matches_value type,value
96
- # puts ">#{type}<{#{type.class}}.matches_value?>#{value.inspect}<{#{value.class}}"
107
+ # puts "matches_value >#{type}<{#{type.class}}.matches_value?>#{value.inspect}<{#{value.class}}"
108
+ if value.class === Class
109
+ return case value.to_s
110
+ when "NilClass" then type == :null
111
+ when "FalseClass", "TrueClass" then type == :boolean
112
+ when "Integer", "Fixnum" then [:uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64].include? type
113
+ when "Float" then [:real32, :real64].include? type
114
+ when "String" then type == :string
115
+ when "Array" then type.array?
116
+ else
117
+ false
118
+ end
119
+ end
97
120
  case value
98
121
  when NilClass
99
122
  true
100
123
  when FalseClass, TrueClass
101
- type == :bool
102
- when Integer
124
+ type == :boolean
125
+ when Integer, Fixnum
103
126
  case type
104
- when :uint8: (0..255) === value
105
- when :sint8: (-128..127) === value
106
- when :uint16: (0..65535) === value
107
- when :sint16: (-32768..32767) === value
108
- when :uint32: (0..4294967295) === value
109
- when :sint32: (-2147483648..2147483647) === value
110
- when :uint64: (0..18446744073709551615) === value
111
- when :sint64: (-9223372036854775808..9223372036854775807) === value
127
+ when :uint8 then (0..255) === value
128
+ when :sint8 then (-128..127) === value
129
+ when :uint16 then (0..65535) === value
130
+ when :sint16 then (-32768..32767) === value
131
+ when :uint32 then (0..4294967295) === value
132
+ when :sint32 then (-2147483648..2147483647) === value
133
+ when :uint64 then (0..18446744073709551615) === value
134
+ when :sint64 then (-9223372036854775808..9223372036854775807) === value
112
135
  else
113
136
  false
114
137
  end
115
138
  when Float
116
139
  case type
117
- when :real32: value.to_i.size == 4
118
- when :real64: true
140
+ when :real32, :real64 then true
119
141
  else
120
142
  false
121
143
  end
@@ -162,6 +184,9 @@ module CIM
162
184
  @size = size
163
185
  super type
164
186
  end
187
+ def array?
188
+ true
189
+ end
165
190
  #
166
191
  # An array is equal to any other array, regardless of the enclosed type
167
192
  #
@@ -31,13 +31,13 @@ module CIM
31
31
  def == v
32
32
  # $stderr.puts "<#{@type}>#{self} == #{v.class}"
33
33
  case v
34
- when NilClass: @type == :null && @value.nil?
35
- when FalseClass: @type == :bool && !@value
36
- when TrueClass: @type == :bool && @value
37
- when String: @type == :string && @value == v
38
- when Integer: @type == :int && @value == v
39
- when Float: @type == :real && @value == v
40
- when CIM::Variant: @type == v.type && @value == v.value
34
+ when NilClass then @type == :null && @value.nil?
35
+ when FalseClass then @type == :boolean && !@value
36
+ when TrueClass then @type == :boolean && @value
37
+ when String then @type == :string && @value == v
38
+ when Integer then @type == :int && @value == v
39
+ when Float then @type == :real && @value == v
40
+ when CIM::Variant then @type == v.type && @value == v.value
41
41
  else
42
42
  false
43
43
  end
@@ -15,10 +15,10 @@ class MethodTest < Test::Unit::TestCase
15
15
  assert_equal false, m.to_s.empty?
16
16
  end
17
17
  def test_nodesc
18
- m = CIM::Method.new :bool, "Foo"
18
+ m = CIM::Method.new :boolean, "Foo"
19
19
  assert m
20
20
  assert_equal "Foo", m.name
21
- assert_equal m.type, :bool
21
+ assert_equal m.type, :boolean
22
22
  # assert_equal nil, m.description
23
23
  end
24
24
  def test_raise
@@ -5,7 +5,7 @@ require "cim"
5
5
 
6
6
  class PropertyTest < Test::Unit::TestCase
7
7
  def test_init
8
- p = CIM::Property.new :string, "String", CIM::QualifierDeclaration.new(:key, :bool), CIM::QualifierDeclaration.new(:description, :string, "This is a string", :class)
8
+ p = CIM::Property.new :string, "String", CIM::QualifierDeclaration.new(:key, :boolean), CIM::QualifierDeclaration.new(:description, :string, "This is a string", :class)
9
9
  assert p
10
10
  assert p.is_a? CIM::Property
11
11
  assert_equal "String", p.name
@@ -5,7 +5,7 @@ require "cim"
5
5
 
6
6
  class QualifierTest < Test::Unit::TestCase
7
7
  def test_key
8
- q = CIM::QualifierDeclaration.new :key, :bool
8
+ q = CIM::QualifierDeclaration.new :key, :boolean
9
9
  assert q
10
10
  end
11
11
  def test_raise
@@ -0,0 +1,19 @@
1
+ $: << File.join(File.dirname(__FILE__),"..","lib")
2
+
3
+ require "test/unit"
4
+ require "cim"
5
+
6
+ class QualifierFlavorsTest < Test::Unit::TestCase
7
+ def test_new
8
+ assert CIM::QualifierFlavors.new
9
+ f = CIM::QualifierFlavors.new(:enableoverride)
10
+ assert f
11
+ assert_equal 1,f.size
12
+ assert f.include? :enableoverride
13
+ end
14
+ def test_raise
15
+ assert_raise CIM::QualifierFlavorError do
16
+ CIM::QualifierFlavors.new(:unknown)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ $: << File.join(File.dirname(__FILE__),"..","lib")
2
+
3
+ require "test/unit"
4
+ require "cim"
5
+
6
+ class QualifierScopesTest < Test::Unit::TestCase
7
+ def test_new
8
+ assert CIM::QualifierScopes.new
9
+ s = CIM::QualifierScopes.new(:association)
10
+ assert s
11
+ assert_equal 1,s.size
12
+ assert s.include? :association
13
+ end
14
+ def test_raise
15
+ assert_raise CIM::QualifierScopeError do
16
+ CIM::QualifierScopes.new(:unknown)
17
+ end
18
+ end
19
+ end
@@ -5,11 +5,11 @@ require "cim"
5
5
 
6
6
  class QualifierSetTest < Test::Unit::TestCase
7
7
  def setup
8
- qbool = CIM::QualifierDeclaration.new("flag")
8
+ qboolean = CIM::QualifierDeclaration.new("flag")
9
9
  qint = CIM::QualifierDeclaration.new("value", :uint32)
10
10
  qstring = CIM::QualifierDeclaration.new("description", :string, "This is a description")
11
11
  @qualifiers = CIM::QualifierSet.new
12
- @qualifiers << CIM::Qualifier.new(qbool)
12
+ @qualifiers << CIM::Qualifier.new(qboolean)
13
13
  @qualifiers << CIM::Qualifier.new(qint)
14
14
  @qualifiers << CIM::Qualifier.new(qstring)
15
15
  end
@@ -18,22 +18,22 @@ class QualifierSetTest < Test::Unit::TestCase
18
18
  end
19
19
  def test_prefill
20
20
  q = CIM::QualifierSet.new "a", :b
21
- assert 2, q.size
21
+ assert_equal 2, q.size
22
22
  assert q.include?( "a" )
23
- assert q.include?( "b", :bool )
23
+ assert q.include?( "b", :boolean )
24
24
  end
25
25
  def test_include
26
26
  assert @qualifiers.include?( :flag )
27
27
  assert @qualifiers.include?( "flag" )
28
- assert @qualifiers.include?( "flag", :bool )
29
- assert @qualifiers.include?( "flag", "bool" )
28
+ assert @qualifiers.include?( "flag", :boolean )
29
+ assert @qualifiers.include?( "flag", "boolean" )
30
30
  assert !@qualifiers.include?( "flag", :string )
31
31
  end
32
32
  def test_access
33
33
  assert @qualifiers[:flag]
34
34
  assert @qualifiers["flag"]
35
- assert @qualifiers["flag", :bool]
36
- assert @qualifiers["flag", "bool"]
35
+ assert @qualifiers["flag", :boolean]
36
+ assert @qualifiers["flag", "boolean"]
37
37
  assert !@qualifiers["flag", :string]
38
38
  end
39
39
  end
@@ -8,10 +8,26 @@ class TypeTest < Test::Unit::TestCase
8
8
  t = CIM::Type.new :null
9
9
  assert t
10
10
  assert_equal "null", t.to_s
11
+ assert !t.array?
11
12
  end
12
13
  def test_raise
13
14
  assert_raise TypeError do
14
15
  t = CIM::Type.new :foo
15
16
  end
16
17
  end
18
+ def test_alias
19
+ assert_equal CIM::Type.new(:bool), CIM::Type.new(:boolean)
20
+ assert_equal CIM::Type.new(:datetime), CIM::Type.new(:dateTime)
21
+ end
22
+ def test_normalize
23
+ assert_equal CIM::Type.new(:null), CIM::Type.normalize(:null)
24
+ assert_equal CIM::Type.normalize(:null), CIM::Type.normalize(CIM::Type.new(:null))
25
+ end
26
+ def test_matches
27
+ assert CIM::Type.new(:null).matches? nil
28
+ assert CIM::Type.new(:uint64).matches? 1
29
+ assert CIM::Type.new(:uint64).matches? Integer
30
+ assert CIM::Type.new(:real32).matches? 3.1415
31
+ assert CIM::Type.new(:string).matches? String
32
+ end
17
33
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cim
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
7
+ - 1
8
+ - 3
9
+ version: "1.3"
11
10
  platform: ruby
12
11
  authors:
13
12
  - "Klaus K\xC3\xA4mpf"
@@ -15,10 +14,37 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-09-29 00:00:00 +02:00
17
+ date: 2012-03-13 00:00:00 +01:00
19
18
  default_executable:
20
- dependencies: []
21
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
22
48
  description: |-
23
49
  Instances of Cim classes are used to define a CIM
24
50
  schema, often represented as a .mof file. See
@@ -41,10 +67,8 @@ files:
41
67
  - Rakefile
42
68
  - cim.gemspec
43
69
  - lib/cim.rb
44
- - lib/cim/association.rb
45
70
  - lib/cim/class.rb
46
71
  - lib/cim/class_feature.rb
47
- - lib/cim/indication.rb
48
72
  - lib/cim/instance.rb
49
73
  - lib/cim/method.rb
50
74
  - lib/cim/named_element.rb
@@ -64,6 +88,8 @@ files:
64
88
  - test/test_method.rb
65
89
  - test/test_property.rb
66
90
  - test/test_qualifier.rb
91
+ - test/test_qualifier_flavors.rb
92
+ - test/test_qualifier_scopes.rb
67
93
  - test/test_qualifier_set.rb
68
94
  - test/test_reference.rb
69
95
  - test/test_type.rb
@@ -97,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
123
  requirements: []
98
124
 
99
125
  rubyforge_project: cim
100
- rubygems_version: 1.5.2
126
+ rubygems_version: 1.5.0
101
127
  signing_key:
102
128
  specification_version: 3
103
129
  summary: A pure-Ruby implementation of the CIM meta model
@@ -106,6 +132,8 @@ test_files:
106
132
  - test/test_method.rb
107
133
  - test/test_property.rb
108
134
  - test/test_qualifier.rb
135
+ - test/test_qualifier_flavors.rb
136
+ - test/test_qualifier_scopes.rb
109
137
  - test/test_qualifier_set.rb
110
138
  - test/test_reference.rb
111
139
  - test/test_type.rb
@@ -1,38 +0,0 @@
1
- #
2
- # cim/association.rb - class CIM::Association
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
- # An Association is a Class with the :association Qualifier
13
- #
14
- # Only such a class can have Reference properties
15
- #
16
- class Association < Class
17
- #
18
- # Create Association class
19
- #
20
- # call-seq:
21
- # Association.new("AssocClass")
22
- # Association.new("AssocClass", qualifiers)
23
- # Association.new("AssocClass", qualifiers, "assoc_class")
24
- # Association.new("AssocClass", qualifiers, "assoc_class", "SuperClass")
25
- # Association.new("AssocClass", qualifiers, "assoc_class", "SuperClass", features)
26
- #
27
- def initialize name, qualifiers = nil, alias_name = nil, superclass = nil, features = nil
28
- raise "Association needs 'association' qualifier" unless qualifiers.include?(:association, :bool)
29
- super name, qualifiers, alias_name, superclass, features
30
- end
31
- #
32
- # true if class has associations (association provider)
33
- #
34
- def association?
35
- true
36
- end
37
- end
38
- end
@@ -1,22 +0,0 @@
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
- #
10
- module CIM
11
- #
12
- # Indication is a Class whose Instances are sending asynchronous notifications
13
- #
14
- class Indication < Class
15
- #
16
- # true if class has indications (indication provider)
17
- #
18
- def indication?
19
- true
20
- end
21
- end
22
- end