Class: Genprovider::Class
- Inherits:
-
Object
- Object
- Genprovider::Class
- Defined in:
- lib/genprovider/class.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#all_features(klass, option) ⇒ Object
yield class features recursively which => nil : all :keys : keys only :nokeys : nokeys only.
-
#initialize(c, out) ⇒ Class
constructor
generate provider code for class ācā.
-
#mkdef(out, feature) ⇒ Object
make feature definition.
-
#mkfeatures(features, out, match) ⇒ Object
generate provider code for features matching match.
-
#mkinitialize(c, out) ⇒ Object
make initializer.
-
#mkmethod(method, out) ⇒ Object
generate code for method.
-
#mkproperty(property, out) ⇒ Object
generate code for property.
-
#mkreference(reference, out) ⇒ Object
generate code for reference.
-
#mkstatic(c, out) ⇒ Object
make static methods.
Constructor Details
#initialize(c, out) ⇒ Class
generate provider code for class ācā
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/genprovider/class.rb', line 165 def initialize c, out out.comment out.comment "Generated by genprovider" out.comment out.puts("require 'cmpi'").puts out.puts("module Cmpi").inc Genprovider::Class.mkdescription out, c if c.superclass out.puts "d = File.dirname(__FILE__)" out.puts "$: << d unless $:.include? d" out.puts "require '#{c.superclass.decamelize}'" end out.comment.comment "Properties:" all_features(c, :keys) { |comment| out.comment "[key] #{comment}" } all_features(c, :nokeys) { |comment| out.comment comment } out.comment out.printf("class #{c.name}") out.write(" < #{c.superclass}") if c.superclass out.puts.inc # class functions mkstatic c, out # initializer mkinitialize c, out # normal properties mkfeatures c.features, out, CIM::Property # reference properties mkfeatures c.features, out, CIM::Reference # methods mkfeatures c.features, out, CIM::Method out.end # class out.end # module end |
Class Method Details
.keyargs(c, out, first = true) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/genprovider/class.rb', line 17 def self.keyargs c, out, first = true keyargs c.parent, first, out if c.parent c.each_key do |k| if first first = false else out.write ", " end out.write(k.name.decamelize) end end |
.mkdescription(out, element) ⇒ Object
11 12 13 14 15 |
# File 'lib/genprovider/class.rb', line 11 def self.mkdescription out, element p = element.qualifiers["description", :string] out.comment out.comment(p.value).comment if p end |
Instance Method Details
#all_features(klass, option) ⇒ Object
yield class features recursively
which => nil : all
:keys : keys only
:nokeys : nokeys only
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/genprovider/class.rb', line 151 def all_features(klass, option) while klass klass.features.each do |f| next if option == :nokeys && f.key? next if option == :keys && !f.key? yield "- #{f.type} #{f.name} (-> #{klass.name})" end klass = klass.parent end end |
#mkdef(out, feature) ⇒ Object
make feature definition
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/genprovider/class.rb', line 68 def mkdef out, feature Genprovider::Class.mkdescription out, feature case feature when CIM::Property # skip when CIM::Reference then out.comment "Reference" when CIM::Method then out.comment "Method" else raise "Unknown feature class #{feature.class}" end out.comment feature.type.to_s + " : " + feature.name out.comment "*Key*" if feature.key? out.comment args = nil if feature.method? feature.parameters.each do |p| args ||= [] if p.qualifiers.include?(:out,:bool) args << "#{p.name.decamelize}_out" else args << p.name.decamelize end end end n = feature.name.decamelize out.def n, args out.puts "@#{n}" out.end if feature.property? && feature.qualifiers.include?(:write) out.def "#{n}=", "_arg" out.puts "@#{n} = _arg" out.end end end |
#mkfeatures(features, out, match) ⇒ Object
generate provider code for features matching match
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/genprovider/class.rb', line 132 def mkfeatures features, out, match features.each do |f| next unless f.instance_of? match case f when CIM::Property then mkproperty f, out when CIM::Reference then mkreference f, out when CIM::Method then mkmethod f, out else raise "Unknown feature class #{f.class}" end end end |
#mkinitialize(c, out) ⇒ Object
make initializer
33 34 35 36 37 38 39 40 |
# File 'lib/genprovider/class.rb', line 33 def mkinitialize c, out out.def "initialize", "reference", "properties" if c.parent out.puts "super reference,properties" end out.end end |
#mkmethod(method, out) ⇒ Object
generate code for method
124 125 126 |
# File 'lib/genprovider/class.rb', line 124 def mkmethod method, out mkdef out, method end |
#mkproperty(property, out) ⇒ Object
generate code for property
108 109 110 |
# File 'lib/genprovider/class.rb', line 108 def mkproperty property, out mkdef out, property end |
#mkreference(reference, out) ⇒ Object
generate code for reference
116 117 118 |
# File 'lib/genprovider/class.rb', line 116 def mkreference reference, out mkdef out, reference end |
#mkstatic(c, out) ⇒ Object
make static methods
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/genprovider/class.rb', line 46 def mkstatic c, out out.comment "each: yield CMPIObjectPath references" out.comment " full => false: set only key properties (instance name)" out.comment " true: with full information to create instances" out.def "self.each", "reference", "properties", "full = false" out.comment "Retrieve names, adapt reference, and yield CMPIObjectPath" out.comment out.comment "YOUR CODE HERE" out.comment out.end out.def "self.delete", "reference", "properties = nil" out.comment "Remove by reference" out.comment out.comment "YOUR CODE HERE" out.comment out.end end |