33: def newtype(name, options = {}, &block)
34:
35: unless options.is_a?(Hash)
36: Puppet.warning "Puppet::Type.newtype(#{name}) now expects a hash as the second argument, not #{options.inspect}"
37: options = {:parent => options}
38: end
39:
40:
41: name = symbolize(name)
42: newmethod = "new#{name.to_s}"
43:
44:
45: selfobj = singleton_class
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:
64: klass = genclass(
65: name,
66: :parent => (parent || Puppet::Type),
67:
68: :overwrite => true,
69: :hash => @types,
70: :attributes => options,
71: &block
72: )
73:
74:
75: if self.respond_to? newmethod
76:
77: Puppet.warning "'new#{name.to_s}' method already exists; skipping"
78: else
79: selfobj.send(:define_method, newmethod) do |*args|
80: klass.new(*args)
81: end
82: end
83:
84:
85:
86: klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure)
87:
88:
89:
90: klass.providerloader = Puppet::Util::Autoload.new(
91: klass,
92:
93: "puppet/provider/#{klass.name.to_s}"
94: )
95:
96:
97: klass.providerloader.loadall
98:
99: klass
100: end