# 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(#{name}) now expects a hash as the second argument, not #{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 = singleton_class
 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: 
 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:     # Now define a "new<type>" method for convenience.
 75:     if self.respond_to? newmethod
 76:       # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
 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:     # If they've got all the necessary methods defined and they haven't
 85:     # already added the property, then do so now.
 86:     klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure)
 87: 
 88:     # Now set up autoload any providers that might exist for this type.
 89: 
 90:           klass.providerloader = Puppet::Util::Autoload.new(
 91:         klass,
 92:         
 93:       "puppet/provider/#{klass.name.to_s}"
 94:     )
 95: 
 96:     # We have to load everything so that we can figure out the default type.
 97:     klass.providerloader.loadall
 98: 
 99:     klass
100:   end