cim 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,14 +7,13 @@ lib/cim/association.rb
7
7
  lib/cim/class.rb
8
8
  lib/cim/indication.rb
9
9
  lib/cim/instance.rb
10
- lib/cim/meta/feature.rb
11
- lib/cim/meta/flavor.rb
12
- lib/cim/meta/named_element.rb
13
- lib/cim/meta/qualifier.rb
14
- lib/cim/meta/schema.rb
15
- lib/cim/meta/scope.rb
16
- lib/cim/meta/type.rb
17
- lib/cim/meta/variant.rb
10
+ lib/cim/class_feature.rb
11
+ lib/cim/qualifier_flavors.rb
12
+ lib/cim/named_element.rb
13
+ lib/cim/qualifier_declaration.rb
14
+ lib/cim/qualifier_scope.rb
15
+ lib/cim/type.rb
16
+ lib/cim/variant.rb
18
17
  lib/cim/method.rb
19
18
  lib/cim/property.rb
20
19
  lib/cim/qualifier.rb
@@ -8,8 +8,11 @@
8
8
 
9
9
  Instances of Cim classes are used to define a CIM schema, often
10
10
  represented as a .mof file.
11
+ See http://www.dmtf.org/standards/cim and http://www.dmtf.org/education/mof
12
+ for details
11
13
 
12
- Hence the primary consumer of Cim is Mofparser, a Ruby based MOF parser.
14
+ https://rubygems.org/gems/mof is a parser for .mof files and the
15
+ primary consumer of the cim gem.
13
16
 
14
17
  == SYNOPSIS:
15
18
 
@@ -30,4 +33,4 @@
30
33
 
31
34
  Copyright (c) 2010 Klaus Kämpf <kkaempf@suse.de>
32
35
 
33
- See http://www.ruby-lang.org/en/LICENSE.txt for the full text
36
+ See http://www.ruby-lang.org/en/LICENSE.txt for the full text
data/lib/cim.rb CHANGED
@@ -8,17 +8,17 @@ $:.unshift(File.dirname(__FILE__)) unless
8
8
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
9
9
 
10
10
  module Cim
11
- VERSION = '0.2.7'
11
+ VERSION = '0.3.0'
12
12
  cim_dir = File.join(File.dirname(__FILE__),"cim")
13
- require cim_dir + '/meta/type'
14
- require cim_dir + '/meta/variant'
15
- require cim_dir + '/meta/flavor'
16
- require cim_dir + '/meta/scope'
17
- require cim_dir + '/meta/named_element'
18
- require cim_dir + '/meta/qualifier'
13
+ require cim_dir + '/type'
14
+ require cim_dir + '/variant'
15
+ require cim_dir + '/qualifier_flavors'
16
+ require cim_dir + '/qualifier_scope'
17
+ require cim_dir + '/named_element'
18
+ require cim_dir + '/qualifier_declaration'
19
19
  require cim_dir + '/qualifier'
20
20
  require cim_dir + '/qualifiers'
21
- require cim_dir + '/meta/feature'
21
+ require cim_dir + '/class_feature'
22
22
  require cim_dir + '/property'
23
23
  require cim_dir + '/reference'
24
24
  require cim_dir + '/method'
@@ -1,4 +1,4 @@
1
- module Cim
1
+ module CIM
2
2
  class Association < Class
3
3
  def initialize name, qualifiers, alias_name, superclass, features
4
4
  raise "Association needs 'association' qualifier" unless qualifiers.include?(:association, :bool)
@@ -1,7 +1,7 @@
1
- module Cim
1
+ module CIM
2
2
  require File.join(File.dirname(__FILE__),"qualifier")
3
- class Class < Cim::Meta::NamedElement
4
- attr_reader :qualifiers, :alias_name, :superclass, :features
3
+ class Class < CIM::NamedElement
4
+ attr_reader :alias_name, :qualifiers, :superclass, :features
5
5
  attr_accessor :parent
6
6
  def initialize name, qualifiers, alias_name, superclass, features
7
7
  @qualifiers = qualifiers
@@ -9,7 +9,7 @@ module Cim
9
9
  @superclass = superclass
10
10
  features = nil if features.is_a?(Array) && features.empty?
11
11
  @features = features
12
- # puts "Cim::Schema::Class.new(#{@features})"
12
+ # puts "CIM::Class.new(#{@features})"
13
13
  super name
14
14
  end
15
15
  def add_type t
@@ -23,7 +23,7 @@ module Cim
23
23
  def method?
24
24
  @features.each do |f|
25
25
  case f
26
- when Cim::Schema::Method: return true
26
+ when CIM::Method: return true
27
27
  end
28
28
  end
29
29
  false
@@ -0,0 +1,43 @@
1
+ module CIM
2
+ # Shared between Property and Method
3
+ class ClassFeature < NamedElement
4
+ attr_reader :type, :qualifiers
5
+ def initialize type, name, qualifiers = nil
6
+ @type = (type.is_a? CIM::Type) ? type : CIM::Type.new(type)
7
+ qualifiers = nil if qualifiers.is_a?(::Array) && qualifiers.empty?
8
+ @qualifiers = qualifiers
9
+ super name
10
+ end
11
+ # if has key qualifier
12
+ def key?
13
+ @qualifiers && @qualifiers.include?(:key,:bool)
14
+ end
15
+ # if static (class-level) feature
16
+ def static?
17
+ false
18
+ end
19
+ # if property
20
+ def property?
21
+ false
22
+ end
23
+ # if method
24
+ def method?
25
+ false
26
+ end
27
+ # if reference
28
+ def reference?
29
+ false
30
+ end
31
+ def to_s
32
+ s = ""
33
+ s << "#{@qualifiers}\n " if @qualifiers
34
+ case @type
35
+ when CIM::Array
36
+ s << "#{@type.type} #{@name}[]"
37
+ else
38
+ s << "#{@type} #{@name}"
39
+ end
40
+ s
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,4 @@
1
- module Cim
1
+ module CIM
2
2
  class Indication < Class
3
3
  # true if class has indications (indication provider)
4
4
  def indication?
@@ -1,5 +1,5 @@
1
- module Cim
2
- class Method < Cim::Meta::Feature
1
+ module CIM
2
+ class Method < CIM::ClassFeature
3
3
  attr_reader :parameters
4
4
  def initialize type, name, qualifiers = nil, parameters = nil
5
5
  parameters = nil if parameters.kind_of?(::Enumerable) && parameters.empty?
@@ -0,0 +1,17 @@
1
+ module CIM
2
+ class NamedElement
3
+ attr_reader :name, :characteristics
4
+ def initialize name
5
+ raise "NamedElement must have a name" unless name
6
+ @name = name.to_s
7
+ @characteristics = []
8
+ end
9
+ def << qualifier
10
+ @characteristics << qualifier
11
+ end
12
+ def has? qualifier
13
+ @characteristics.include? qualifier
14
+ end
15
+ end
16
+ end
17
+
@@ -1,5 +1,5 @@
1
- module Cim
2
- class Property < Cim::Meta::Feature
1
+ module CIM
2
+ class Property < CIM::ClassFeature
3
3
  attr_reader :default
4
4
  def initialize type, name, qualifiers=nil, default=nil
5
5
  @default = default
@@ -8,6 +8,9 @@ module Cim
8
8
  end
9
9
  super type, name, qualifiers
10
10
  end
11
+ def property?
12
+ true
13
+ end
11
14
  end
12
15
  end
13
16
 
@@ -1,32 +1,32 @@
1
- module Cim
1
+ module CIM
2
2
  class Qualifier
3
- attr_reader :definition, :value, :flavor
4
- def initialize definition, value = nil, flavor = nil
5
- raise "Not a Cim::Meta::Qualifier definition: #{definition.inspect}" unless definition.is_a?(Cim::Meta::Qualifier)
6
- @definition = definition
3
+ attr_reader :declaration, :value, :flavor
4
+ def initialize declaration, value = nil, flavor = nil
5
+ raise "Not a CIM::QualifierDeclaration: #{declaration.inspect}" unless declaration.is_a?(CIM::QualifierDeclaration)
6
+ @declaration = declaration
7
7
  @value = value
8
8
  @flavor = flavor
9
9
  end
10
10
  def == q
11
- # puts "Cim::Schema::Qualifier ->#{self} == #{q.inspect}"
11
+ # puts "CIM::Qualifier ->#{self} == #{q.inspect}"
12
12
  case q
13
- when Cim::Schema::Qualifier
14
- (@definition == q.definition) &&
13
+ when CIM::Qualifier
14
+ (@declaration == q.declaration) &&
15
15
  (@value == q.value) &&
16
16
  (@flavor == q.flavor)
17
- when Cim::Meta::Qualifier
18
- @definition == q
17
+ when CIM::QualifierDeclaration
18
+ @declaration == q
19
19
  when Symbol
20
- q.to_s.downcase == @definition.name.downcase && @value.nil? && @flavor.nil?
20
+ q.to_s.downcase == @declaration.name.downcase && @value.nil? && @flavor.nil?
21
21
  else
22
22
  false
23
23
  end
24
24
  end
25
25
  def to_sym
26
- @definition.downcase.to_sym
26
+ @declaration.downcase.to_sym
27
27
  end
28
28
  def to_s
29
- s = "#{@definition.name.capitalize}"
29
+ s = "#{@declaration.name.capitalize}"
30
30
  case @value
31
31
  when nil:
32
32
  when Array:
@@ -0,0 +1,32 @@
1
+ module CIM
2
+ class QualifierDeclaration < NamedElement
3
+
4
+ attr_reader :type, :default, :scope, :flavor
5
+
6
+ def initialize name, type = :bool, default = false, scope = nil, flavor = nil
7
+ @type = (type.kind_of? Type) ? type : Type.new(type)
8
+ @default = (default.nil? || default.is_a?(CIM::Variant)) ? default : CIM::Variant.new(@type, default)
9
+ @scope = scope
10
+ @flavor = flavor
11
+ super name
12
+ end
13
+
14
+ def == q
15
+ # puts "#{@name}:#{@type} == #{q.name}:#{q.type}"
16
+ (@name.downcase == q.name.downcase) &&
17
+ (@type.nil? || q.type.nil? || (@type == q.type))
18
+ end
19
+
20
+ def to_sym
21
+ @name.downcase.to_sym
22
+ end
23
+
24
+ def to_s
25
+ s = "Qualifier #{@name} : #{@type}"
26
+ s << " = #{@default}" if @default
27
+ s << ",\n\t#{@scope}" if @scope
28
+ s << ",\n\t#{@flavor}" if @flavor
29
+ s
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module CIM
2
+
3
+ class QualifierFlavorError < ArgumentError
4
+ def initialize flavor
5
+ @flavor = flavor
6
+ end
7
+ def to_s
8
+ "#{@flavor} is not a valid qualifier flavor"
9
+ end
10
+ end
11
+
12
+ class QualifierFlavors
13
+ FLAVORS = [:amended, :enableoverride, :disableoverride, :restricted, :toinstance, :tosubclass, :translatable]
14
+ attr_reader :flavors
15
+ def initialize flavor
16
+ @flavors = []
17
+ self << flavor
18
+ end
19
+ def << flavor
20
+ flavor.downcase! if flavor.kind_of? String
21
+ f = flavor.to_sym
22
+ raise QualifierFlavorError.new("#{flavor}") unless FLAVORS.include? f
23
+ @flavors << f
24
+ self
25
+ end
26
+ def to_sym
27
+ @flavors.first
28
+ end
29
+ def to_s
30
+ "Flavor(#{@flavors.join(', ')})"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ module CIM
2
+
3
+ class QualifierScopeError < ArgumentError
4
+ def initialize element, msg = nil
5
+ @element = element
6
+ super msg
7
+ end
8
+ def to_s
9
+ "#{@element} is not a valid meta element for scopes"
10
+ end
11
+ end
12
+
13
+ class QualifierScope
14
+ META_ELEMENTS = [ :schema, :class, :association, :indication, :qualifier, :property, :reference, :method, :parameter, :any ]
15
+ attr_reader :elements
16
+ def initialize element = :any
17
+ @elements = []
18
+ self << element
19
+ end
20
+ def << element
21
+ element.downcase! if element.is_a?(String)
22
+ e = element.to_sym
23
+ raise QualifierScopeError.new(element) unless META_ELEMENTS.include?(e)
24
+ @elements << e
25
+ self
26
+ end
27
+ def has? qualifier
28
+ @elements.include? qualifier
29
+ end
30
+ def to_s
31
+ "Scope(#{@elements.join(', ')})"
32
+ end
33
+ def to_sym
34
+ @elements.first
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,6 @@
1
- module Cim
2
- # Array of Cim::Schema::Qualifier
3
- class Qualifiers < Array
1
+ module CIM
2
+ # Array of CIM::Qualifier
3
+ class Qualifiers < ::Array
4
4
  #
5
5
  # check if qualifier exists
6
6
  #
@@ -8,14 +8,14 @@ module Cim
8
8
  def include? q,type=:null
9
9
  # puts "#{self}.include? #{q}:#{type}"
10
10
  case q
11
- when Cim::Schema::Qualifier
11
+ when CIM::Qualifier
12
12
  q = q.definition
13
- when Cim::Meta::Qualifier
13
+ when CIM::QualifierDeclaration
14
14
  # nothing
15
15
  when String
16
- q = Cim::Meta::Qualifier.new(q,type)
16
+ q = CIM::QualifierDeclaration.new(q,type)
17
17
  when Symbol
18
- q = Cim::Meta::Qualifier.new(q,type)
18
+ q = CIM::QualifierDeclaration.new(q,type)
19
19
  else
20
20
  raise "Unknown parameter in #{self.class}.include?"
21
21
  end
@@ -29,14 +29,14 @@ module Cim
29
29
  case q
30
30
  when Fixnum
31
31
  return self.array_access[q]
32
- when Cim::Schema::Qualifier
32
+ when CIM::Qualifier
33
33
  q = q.definition
34
- when Cim::Meta::Qualifier
34
+ when CIM::QualifierDeclaration
35
35
  # nothing
36
36
  when String
37
- q = Cim::Meta::Qualifier.new(q,type)
37
+ q = CIM::QualifierDeclaration.new(q,type)
38
38
  when Symbol
39
- q = Cim::Meta::Qualifier.new(q,type)
39
+ q = CIM::QualifierDeclaration.new(q,type)
40
40
  else
41
41
  raise "Unknown parameter in #{self.class}.[]"
42
42
  end
@@ -1,5 +1,5 @@
1
- module Cim
2
- class Reference < Property
1
+ module CIM
2
+ class Reference < CIM::Property
3
3
  def reference?
4
4
  true
5
5
  end
@@ -0,0 +1,122 @@
1
+ module CIM
2
+ class Type
3
+ TYPES = [:null,:void,:bool,:char16,:string,:uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64,:real32,:real64,:datetime,:class,:reference,:array]
4
+ MATCHES = {
5
+ :null => [],
6
+ :void => [], # WMI
7
+ :bool => [],
8
+ :char16 => [ :null, :string ],
9
+ :string => [ :null ],
10
+ :uint8 => [ :null ],
11
+ :sint8 => [ :null ],
12
+ :uint16 => [ :null, :uint8 ],
13
+ :sint16 => [ :null, :sint8 ],
14
+ :uint32 => [ :null, :uint8, :uint16 ],
15
+ :sint32 => [ :null, :sint8, :sint16 ],
16
+ :uint64 => [ :null, :uint8, :uint16, :sint32 ],
17
+ :sint64 => [ :null, :sint8, :sint16, :sint32 ],
18
+ :real32 => [ :null ],
19
+ :real64 => [ :null, :real32 ],
20
+ :datetime => [ :null ],
21
+ :class => [ :null ],
22
+ :reference => [ :null ],
23
+ :array => [ :null ]
24
+ }
25
+ attr_reader :type
26
+ def initialize type
27
+ type.downcase! if type.is_a? String
28
+ @type = type.to_sym
29
+ raise TypeError.new("#{type}") unless TYPES.include? @type
30
+ end
31
+ def to_s
32
+ @type.to_s
33
+ end
34
+ def to_sym
35
+ @type
36
+ end
37
+ def == t
38
+ case t
39
+ when Type: t.type == @type
40
+ when Symbol: t == @type
41
+ else
42
+ false
43
+ end
44
+ end
45
+ private
46
+ def matches_value type,value
47
+ # puts ">#{type}<{#{type.class}}.matches_value?>#{value.inspect}<{#{value.class}}"
48
+ case value
49
+ when NilClass
50
+ true
51
+ when FalseClass, TrueClass
52
+ type == :bool
53
+ when Integer
54
+ case type
55
+ when :uint8: (0..255) === value
56
+ when :sint8: (-128..127) === value
57
+ when :uint16: (0..65535) === value
58
+ when :sint16: (-32768..32767) === value
59
+ when :uint32: (0..4294967295) === value
60
+ when :sint32: (-2147483648..2147483647) === value
61
+ when :uint64: (0..18446744073709551615) === value
62
+ when :sint64: (-9223372036854775808..9223372036854775807) === value
63
+ else
64
+ false
65
+ end
66
+ when Float
67
+ case type
68
+ when :real32: value.to_i.size == 4
69
+ when :real64: true
70
+ else
71
+ false
72
+ end
73
+ when String
74
+ type == :string
75
+ else
76
+ false
77
+ end
78
+ end
79
+ public
80
+ def matches? x
81
+ # puts ">#{self}<{#{self.class}}.matches?>#{x.inspect}<{#{x.class}}"
82
+ case x
83
+ when CIM::Type, CIM::Variant
84
+ return true if x.type == @type
85
+ return true if MATCHES[@type].include? x.type
86
+ false
87
+ when ::Array
88
+ return false unless self.is_a? CIM::Array
89
+ x.each do |v|
90
+ return false unless matches_value @type,v
91
+ end
92
+ true
93
+ else
94
+ matches_value @type, x
95
+ end
96
+ end
97
+ end
98
+ class Array < Type
99
+ attr_reader :size
100
+ def initialize size, type
101
+ @size = size
102
+ super type
103
+ end
104
+ def to_s
105
+ if @size > 0
106
+ "#{super}[#{@size}]"
107
+ else
108
+ "#{super}[]"
109
+ end
110
+ end
111
+ end
112
+ class ReferenceType < Type
113
+ attr_reader :name
114
+ def initialize name
115
+ @name = name
116
+ super :class
117
+ end
118
+ def to_s
119
+ "#{@name} ref"
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,17 @@
1
+ module CIM
2
+ # A Variant is a typed value
3
+ class Variant
4
+ attr_reader :type, :value
5
+ def initialize type = :null, value = nil
6
+ @type = (type.kind_of? CIM::Type) ? type : CIM::Type.new(type)
7
+ @value = value unless value == :null
8
+ end
9
+ def to_s
10
+ if @type == :null
11
+ "null"
12
+ else
13
+ "#{@value.inspect}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,7 +5,7 @@ require "cim"
5
5
 
6
6
  class MethodTest < Test::Unit::TestCase
7
7
  def test_init
8
- m = Cim::Method.new :real32, "Foo", Cim::Meta::Qualifier.new(:description, :string, "This is a foo method", :class)
8
+ m = CIM::Method.new :real32, "Foo", CIM::QualifierDeclaration.new(:description, :string, "This is a foo method", :class)
9
9
  assert m
10
10
  assert_equal "Foo", m.name
11
11
  assert m.qualifiers.size > 0
@@ -14,7 +14,7 @@ class MethodTest < Test::Unit::TestCase
14
14
  assert_equal false, m.to_s.empty?
15
15
  end
16
16
  def test_nodesc
17
- m = Cim::Method.new :bool, "Foo"
17
+ m = CIM::Method.new :bool, "Foo"
18
18
  assert m
19
19
  assert_equal "Foo", m.name
20
20
  assert_equal m.type, :bool
@@ -22,7 +22,7 @@ class MethodTest < Test::Unit::TestCase
22
22
  end
23
23
  def test_raise
24
24
  assert_raise TypeError do
25
- m = Cim::Method.new :foo, "Foo"
25
+ m = CIM::Method.new :foo, "Foo"
26
26
  end
27
27
  end
28
28
  end
@@ -5,19 +5,19 @@ require "cim"
5
5
 
6
6
  class PropertyTest < Test::Unit::TestCase
7
7
  def test_init
8
- p = Cim::Property.new :string, "String", Cim::Meta::Qualifier.new(:key, :bool), Cim::Meta::Qualifier.new(:description, :string, "This is a string", :class)
8
+ p = CIM::Property.new :string, "String", CIM::QualifierDeclaration.new(:key, :bool), CIM::QualifierDeclaration.new(:description, :string, "This is a string", :class)
9
9
  assert p
10
- assert p.is_a? Cim::Property
10
+ assert p.is_a? CIM::Property
11
11
  assert_equal "String", p.name
12
12
  # assert p.key?
13
13
  end
14
14
  def test_name
15
- p = Cim::Property.new :uint32, "foo"
15
+ p = CIM::Property.new :uint32, "foo"
16
16
  assert_equal "foo", p.name
17
17
  end
18
18
  def test_raise
19
19
  assert_raise TypeError do
20
- p = Cim::Property.new :foo, "foo"
20
+ p = CIM::Property.new :foo, "foo"
21
21
  end
22
22
  end
23
23
  end
@@ -5,12 +5,12 @@ require "cim"
5
5
 
6
6
  class QualifierTest < Test::Unit::TestCase
7
7
  def test_key
8
- q = Cim::Meta::Qualifier.new :key, :bool
8
+ q = CIM::QualifierDeclaration.new :key, :bool
9
9
  assert q
10
10
  end
11
11
  def test_raise
12
12
  assert_raise RuntimeError do
13
- Cim::Qualifier.new(:unknown)
13
+ CIM::Qualifier.new(:unknown)
14
14
  end
15
15
  end
16
16
  end
@@ -5,9 +5,9 @@ require "cim"
5
5
 
6
6
  class ReferenceTest < Test::Unit::TestCase
7
7
  def test_init
8
- r = Cim::Reference.new :string, "String"
8
+ r = CIM::Reference.new :string, "String"
9
9
  assert r
10
- assert r.is_a? Cim::Reference
11
- assert r.kind_of? Cim::Property
10
+ assert r.is_a? CIM::Reference
11
+ assert r.kind_of? CIM::ClassFeature
12
12
  end
13
13
  end
@@ -5,13 +5,13 @@ require "cim"
5
5
 
6
6
  class TypeTest < Test::Unit::TestCase
7
7
  def test_init
8
- t = Cim::Meta::Type.new :null
8
+ t = CIM::Type.new :null
9
9
  assert t
10
10
  assert_equal "null", t.to_s
11
11
  end
12
12
  def test_raise
13
13
  assert_raise TypeError do
14
- t = Cim::Meta::Type.new :foo
14
+ t = CIM::Type.new :foo
15
15
  end
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cim
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 7
10
- version: 0.2.7
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Klaus K\xC3\xA4mpf"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-03 00:00:00 +02:00
18
+ date: 2010-10-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,8 +55,11 @@ description: |-
55
55
 
56
56
  Instances of Cim classes are used to define a CIM schema, often
57
57
  represented as a .mof file.
58
+ See http://www.dmtf.org/standards/cim and http://www.dmtf.org/education/mof
59
+ for details
58
60
 
59
- Hence the primary consumer of Cim is Mofparser, a Ruby based MOF parser.
61
+ https://rubygems.org/gems/mof is a parser for .mof files and the
62
+ primary consumer of the cim gem.
60
63
  email:
61
64
  - kkaempf@suse.de
62
65
  executables: []
@@ -76,14 +79,13 @@ files:
76
79
  - lib/cim/class.rb
77
80
  - lib/cim/indication.rb
78
81
  - lib/cim/instance.rb
79
- - lib/cim/meta/feature.rb
80
- - lib/cim/meta/flavor.rb
81
- - lib/cim/meta/named_element.rb
82
- - lib/cim/meta/qualifier.rb
83
- - lib/cim/meta/schema.rb
84
- - lib/cim/meta/scope.rb
85
- - lib/cim/meta/type.rb
86
- - lib/cim/meta/variant.rb
82
+ - lib/cim/class_feature.rb
83
+ - lib/cim/qualifier_flavors.rb
84
+ - lib/cim/named_element.rb
85
+ - lib/cim/qualifier_declaration.rb
86
+ - lib/cim/qualifier_scope.rb
87
+ - lib/cim/type.rb
88
+ - lib/cim/variant.rb
87
89
  - lib/cim/method.rb
88
90
  - lib/cim/property.rb
89
91
  - lib/cim/qualifier.rb
@@ -132,8 +134,8 @@ specification_version: 3
132
134
  summary: "* Cim is a pure-Ruby implementation of the CIM meta model"
133
135
  test_files:
134
136
  - test/test_qualifier.rb
135
- - test/test_method.rb
137
+ - test/test_loading.rb
136
138
  - test/test_property.rb
137
139
  - test/test_type.rb
138
- - test/test_loading.rb
140
+ - test/test_method.rb
139
141
  - test/test_reference.rb
@@ -1,41 +0,0 @@
1
- module Cim
2
- module Meta
3
- # Shared between Property and Method
4
- class Feature < NamedElement
5
- attr_reader :type, :qualifiers
6
- def initialize type, name, qualifiers
7
- @type = (type.is_a? Cim::Meta::Type) ? type : Cim::Meta::Type.new(type)
8
- qualifiers = nil if qualifiers.is_a?(::Array) && qualifiers.empty?
9
- @qualifiers = qualifiers
10
- super name
11
- end
12
- # if has key qualifier
13
- def key?
14
- @qualifiers && @qualifiers.include?(:key,:bool)
15
- end
16
- # if static (class-level) feature
17
- def static?
18
- false
19
- end
20
- # if method
21
- def method?
22
- false
23
- end
24
- # if reference
25
- def reference?
26
- false
27
- end
28
- def to_s
29
- s = ""
30
- s << "#{@qualifiers}\n " if @qualifiers
31
- case @type
32
- when Cim::Meta::Array
33
- s << "#{@type.type} #{@name}[]"
34
- else
35
- s << "#{@type} #{@name}"
36
- end
37
- s
38
- end
39
- end
40
- end
41
- end
@@ -1,33 +0,0 @@
1
- module Cim
2
- module Meta
3
- class FlavorError < ArgumentError
4
- def initialize flavor
5
- @flavor = flavor
6
- end
7
- def to_s
8
- "#{@flavor} is not a valid Flavor"
9
- end
10
- end
11
- class Flavors
12
- FLAVORS = [:amended, :enableoverride, :disableoverride, :restricted, :toinstance, :tosubclass, :translatable]
13
- attr_reader :flavors
14
- def initialize flavor
15
- @flavors = []
16
- self << flavor
17
- end
18
- def << flavor
19
- flavor.downcase! if flavor.kind_of? String
20
- f = flavor.to_sym
21
- raise FlavorError.new("#{flavor}") unless FLAVORS.include? f
22
- @flavors << f
23
- self
24
- end
25
- def to_sym
26
- @flavors.first
27
- end
28
- def to_s
29
- "Flavor(#{@flavors.join(', ')})"
30
- end
31
- end
32
- end
33
- end
@@ -1,18 +0,0 @@
1
- module Cim
2
- module Meta
3
- class NamedElement
4
- attr_reader :name, :characteristics
5
- def initialize name
6
- raise "NamedElement must have a name" unless name
7
- @name = name.to_s
8
- @characteristics = []
9
- end
10
- def << qualifier
11
- @characteristics << qualifier
12
- end
13
- def has? qualifier
14
- @characteristics.include? qualifier
15
- end
16
- end
17
- end
18
- end
@@ -1,34 +0,0 @@
1
- module Cim
2
- module Meta
3
- class Qualifier < NamedElement
4
-
5
- attr_reader :type, :default, :scope, :flavor
6
-
7
- def initialize name, type = :bool, default = false, scope = nil, flavor = nil
8
- @type = (type.kind_of? Type) ? type : Type.new(type)
9
- @default = (default.nil? || default.is_a?(Cim::Meta::Variant)) ? default : Cim::Meta::Variant.new(@type, default)
10
- @scope = scope
11
- @flavor = flavor
12
- super name
13
- end
14
-
15
- def == q
16
- # puts "#{@name}:#{@type} == #{q.name}:#{q.type}"
17
- (@name.downcase == q.name.downcase) &&
18
- (@type.nil? || q.type.nil? || (@type == q.type))
19
- end
20
-
21
- def to_sym
22
- @name.downcase.to_sym
23
- end
24
-
25
- def to_s
26
- s = "Qualifier #{@name} : #{@type}"
27
- s << " = #{@default}" if @default
28
- s << ",\n\t#{@scope}" if @scope
29
- s << ",\n\t#{@flavor}" if @flavor
30
- s
31
- end
32
- end
33
- end
34
- end
@@ -1,7 +0,0 @@
1
- module Cim
2
- module Meta
3
- class Schema < NamedElement
4
- # Class schema
5
- end
6
- end
7
- end
@@ -1,39 +0,0 @@
1
- module Cim
2
- module Meta
3
-
4
- class MetaElementError < ArgumentError
5
- def initialize element, msg = nil
6
- @element = element
7
- super msg
8
- end
9
- def to_s
10
- "#{@element} is not a valid meta element for scopes"
11
- end
12
- end
13
-
14
- class Scope
15
- META_ELEMENTS = [ :schema, :class, :association, :indication, :qualifier, :property, :reference, :method, :parameter, :any ]
16
- attr_reader :elements
17
- def initialize element = :any
18
- @elements = []
19
- self << element
20
- end
21
- def << element
22
- element.downcase! if element.is_a?(String)
23
- e = element.to_sym
24
- raise MetaElementError.new(element) unless META_ELEMENTS.include?(e)
25
- @elements << e
26
- self
27
- end
28
- def has? qualifier
29
- @elements.include? qualifier
30
- end
31
- def to_s
32
- "Scope(#{@elements.join(', ')})"
33
- end
34
- def to_sym
35
- @elements.first
36
- end
37
- end
38
- end
39
- end
@@ -1,124 +0,0 @@
1
- module Cim
2
- module Meta
3
- class Type
4
- TYPES = [:null,:void,:bool,:char16,:string,:uint8,:sint8,:uint16,:sint16,:uint32,:sint32,:uint64,:sint64,:real32,:real64,:datetime,:class,:reference,:array]
5
- MATCHES = {
6
- :null => [],
7
- :void => [], # WMI
8
- :bool => [],
9
- :char16 => [ :null, :string ],
10
- :string => [ :null ],
11
- :uint8 => [ :null ],
12
- :sint8 => [ :null ],
13
- :uint16 => [ :null, :uint8 ],
14
- :sint16 => [ :null, :sint8 ],
15
- :uint32 => [ :null, :uint8, :uint16 ],
16
- :sint32 => [ :null, :sint8, :sint16 ],
17
- :uint64 => [ :null, :uint8, :uint16, :sint32 ],
18
- :sint64 => [ :null, :sint8, :sint16, :sint32 ],
19
- :real32 => [ :null ],
20
- :real64 => [ :null, :real32 ],
21
- :datetime => [ :null ],
22
- :class => [ :null ],
23
- :reference => [ :null ],
24
- :array => [ :null ]
25
- }
26
- attr_reader :type
27
- def initialize type
28
- type.downcase! if type.is_a? String
29
- @type = type.to_sym
30
- raise TypeError.new("#{type}") unless TYPES.include? @type
31
- end
32
- def to_s
33
- @type.to_s
34
- end
35
- def to_sym
36
- @type
37
- end
38
- def == t
39
- case t
40
- when Type: t.type == @type
41
- when Symbol: t == @type
42
- else
43
- false
44
- end
45
- end
46
- private
47
- def matches_value type,value
48
- # puts ">#{type}<{#{type.class}}.matches_value?>#{value.inspect}<{#{value.class}}"
49
- case value
50
- when NilClass
51
- true
52
- when FalseClass, TrueClass
53
- type == :bool
54
- when Integer
55
- case type
56
- when :uint8: (0..255) === value
57
- when :sint8: (-128..127) === value
58
- when :uint16: (0..65535) === value
59
- when :sint16: (-32768..32767) === value
60
- when :uint32: (0..4294967295) === value
61
- when :sint32: (-2147483648..2147483647) === value
62
- when :uint64: (0..18446744073709551615) === value
63
- when :sint64: (-9223372036854775808..9223372036854775807) === value
64
- else
65
- false
66
- end
67
- when Float
68
- case type
69
- when :real32: value.to_i.size == 4
70
- when :real64: true
71
- else
72
- false
73
- end
74
- when String
75
- type == :string
76
- else
77
- false
78
- end
79
- end
80
- public
81
- def matches? x
82
- # puts ">#{self}<{#{self.class}}.matches?>#{x.inspect}<{#{x.class}}"
83
- case x
84
- when Cim::Meta::Type, Cim::Meta::Variant
85
- return true if x.type == @type
86
- return true if MATCHES[@type].include? x.type
87
- false
88
- when ::Array
89
- return false unless self.is_a? Cim::Meta::Array
90
- x.each do |v|
91
- return false unless matches_value @type,v
92
- end
93
- true
94
- else
95
- matches_value @type, x
96
- end
97
- end
98
- end
99
- class Array < Type
100
- attr_reader :size
101
- def initialize size, type
102
- @size = size
103
- super type
104
- end
105
- def to_s
106
- if @size > 0
107
- "#{super}[#{@size}]"
108
- else
109
- "#{super}[]"
110
- end
111
- end
112
- end
113
- class Reference < Type
114
- attr_reader :name
115
- def initialize name
116
- @name = name
117
- super :class
118
- end
119
- def to_s
120
- "#{@name} ref"
121
- end
122
- end
123
- end
124
- end
@@ -1,19 +0,0 @@
1
- module Cim
2
- module Meta
3
- # A Variant is a typed value
4
- class Variant
5
- attr_reader :type, :value
6
- def initialize type = :null, value = nil
7
- @type = (type.kind_of? Cim::Meta::Type) ? type : Cim::Meta::Type.new(type)
8
- @value = value unless value == :null
9
- end
10
- def to_s
11
- if @type == :null
12
- "null"
13
- else
14
- "#{@value.inspect}"
15
- end
16
- end
17
- end
18
- end
19
- end