33: def newtype(name, options = {}, &block)
34:
35: unless options.is_a?(Hash)
36: Puppet.warning "Puppet::Type.newtype(%s) now expects a hash as the second argument, not %s" % [name, options.inspect]
37: options = {:parent => options}
38: end
39:
40:
41: name = symbolize(name)
42: newmethod = "new#{name.to_s}"
43:
44:
45: selfobj = metaclass()
46:
47: @types ||= {}
48:
49: if @types.include?(name)
50: if self.respond_to?(newmethod)
51:
52: selfobj.send(:remove_method,newmethod)
53: end
54: end
55:
56: options = symbolize_options(options)
57:
58: if parent = options[:parent]
59: options.delete(:parent)
60: end
61:
62:
63: klass = genclass(name,
64: :parent => (parent || Puppet::Type),
65: :overwrite => true,
66: :hash => @types,
67: :attributes => options,
68: &block
69: )
70:
71:
72: if self.respond_to? newmethod
73:
74: Puppet.warning "'new#{name.to_s}' method already exists; skipping"
75: else
76: selfobj.send(:define_method, newmethod) do |*args|
77: klass.create(*args)
78: end
79: end
80:
81:
82:
83: if klass.ensurable? and ! klass.validproperty?(:ensure)
84: klass.ensurable
85: end
86:
87:
88: klass.providerloader = Puppet::Util::Autoload.new(klass,
89: "puppet/provider/#{klass.name.to_s}"
90: )
91:
92:
93: klass.providerloader.loadall()
94:
95: klass
96: end