# File lib/puppet/metatype/manager.rb, line 33
33:     def newtype(name, options = {}, &block)
34:         # Handle backward compatibility
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:         # First make sure we don't have a method sitting around
41:         name = symbolize(name)
42:         newmethod = "new#{name.to_s}"
43: 
44:         # Used for method manipulation.
45:         selfobj = metaclass()
46: 
47:         @types ||= {}
48: 
49:         if @types.include?(name)
50:             if self.respond_to?(newmethod)
51:                 # Remove the old newmethod
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:         # Then create the class.
63:         klass = genclass(name,
64:             :parent => (parent || Puppet::Type),
65:             :overwrite => true,
66:             :hash => @types,
67:             :attributes => options,
68:             &block
69:         )
70: 
71:         # Now define a "new<type>" method for convenience.
72:         if self.respond_to? newmethod
73:             # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
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:         # If they've got all the necessary methods defined and they haven't
82:         # already added the property, then do so now.
83:         if klass.ensurable? and ! klass.validproperty?(:ensure)
84:             klass.ensurable
85:         end
86: 
87:         # Now set up autoload any providers that might exist for this type.
88:         klass.providerloader = Puppet::Util::Autoload.new(klass,
89:             "puppet/provider/#{klass.name.to_s}"
90:         )
91: 
92:         # We have to load everything so that we can figure out the default type.
93:         klass.providerloader.loadall()
94: 
95:         klass
96:     end