Removing long-deprecated code and fixing
some indentation.

Also moving the lib/puppet/manager/ code back into Puppet::Type - I
moved it out years ago, and it doesn't actually provide any value being
in a separate file.

Signed-off-by: Luke Kanies <[email protected]>
---
Local-branch: refactor/master/8233-refactor_parameter_management
 lib/puppet/metatype/manager.rb |  134 --------------------
 lib/puppet/transportable.rb    |    2 +-
 lib/puppet/type.rb             |  264 +++++++++++++++++++++-------------------
 spec/integration/type_spec.rb  |   32 -----
 spec/unit/transaction_spec.rb  |    2 +-
 spec/unit/type_spec.rb         |   32 +++++
 test/ral/manager/manager.rb    |   54 --------
 7 files changed, 171 insertions(+), 349 deletions(-)
 delete mode 100644 lib/puppet/metatype/manager.rb
 delete mode 100755 spec/integration/type_spec.rb
 delete mode 100755 test/ral/manager/manager.rb

diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb
deleted file mode 100644
index 597a89f..0000000
--- a/lib/puppet/metatype/manager.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-require 'puppet'
-require 'puppet/util/classgen'
-
-# Methods dealing with Type management.  This module gets included into the
-# Puppet::Type class, it's just split out here for clarity.
-module Puppet::MetaType
-module Manager
-  include Puppet::Util::ClassGen
-
-  # remove all type instances; this is mostly only useful for testing
-  def allclear
-    @types.each { |name, type|
-      type.clear
-    }
-  end
-
-  # iterate across all of the subclasses of Type
-  def eachtype
-    @types.each do |name, type|
-      # Only consider types that have names
-      #if ! type.parameters.empty? or ! type.validproperties.empty?
-        yield type
-      #end
-    end
-  end
-
-  # Load all types.  Only currently used for documentation.
-  def loadall
-    typeloader.loadall
-  end
-
-  # Define a new type.
-  def newtype(name, options = {}, &block)
-    # Handle backward compatibility
-    unless options.is_a?(Hash)
-      Puppet.warning "Puppet::Type.newtype(#{name}) now expects a hash as the 
second argument, not #{options.inspect}"
-      options = {:parent => options}
-    end
-
-    # First make sure we don't have a method sitting around
-    name = symbolize(name)
-    newmethod = "new#{name.to_s}"
-
-    # Used for method manipulation.
-    selfobj = singleton_class
-
-    @types ||= {}
-
-    if @types.include?(name)
-      if self.respond_to?(newmethod)
-        # Remove the old newmethod
-        selfobj.send(:remove_method,newmethod)
-      end
-    end
-
-    options = symbolize_options(options)
-
-    if parent = options[:parent]
-      options.delete(:parent)
-    end
-
-    # Then create the class.
-
-    klass = genclass(
-      name,
-      :parent => (parent || Puppet::Type),
-      :overwrite => true,
-      :hash => @types,
-      :attributes => options,
-      &block
-    )
-
-    # Now define a "new<type>" method for convenience.
-    if self.respond_to? newmethod
-      # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
-      Puppet.warning "'new#{name.to_s}' method already exists; skipping"
-    else
-      selfobj.send(:define_method, newmethod) do |*args|
-        klass.new(*args)
-      end
-    end
-
-    # If they've got all the necessary methods defined and they haven't
-    # already added the property, then do so now.
-    klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure)
-
-    # Now set up autoload any providers that might exist for this type.
-
-    klass.providerloader = Puppet::Util::Autoload.new(klass, 
"puppet/provider/#{klass.name.to_s}")
-
-    # We have to load everything so that we can figure out the default 
provider.
-    klass.providerloader.loadall
-    klass.providify unless klass.providers.empty?
-
-    klass
-  end
-
-  # Remove an existing defined type.  Largely used for testing.
-  def rmtype(name)
-    # Then create the class.
-
-    klass = rmclass(name, :hash => @types)
-
-    singleton_class.send(:remove_method, "new#{name}") if 
respond_to?("new#{name}")
-  end
-
-  # Return a Type instance by name.
-  def type(name)
-    @types ||= {}
-
-    name = name.to_s.downcase.to_sym
-
-    if t = @types[name]
-      return t
-    else
-      if typeloader.load(name)
-        Puppet.warning "Loaded puppet/type/#{name} but no class was created" 
unless @types.include? name
-      end
-
-      return @types[name]
-    end
-  end
-
-  # Create a loader for Puppet types.
-  def typeloader
-    unless defined?(@typeloader)
-      @typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => 
false)
-    end
-
-    @typeloader
-  end
-end
-end
-
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index f7b839c..38f390c 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -51,7 +51,7 @@ module Puppet
         trans[param] = value
       }
       trans.catalog = self.catalog
-      Puppet::Type::Component.create(trans)
+      Puppet::Type::Component.new(trans)
     end
 
     def to_hash
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 15f340f..5469741 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -5,7 +5,6 @@ require 'puppet/property'
 require 'puppet/parameter'
 require 'puppet/util'
 require 'puppet/util/autoload'
-require 'puppet/metatype/manager'
 require 'puppet/util/errors'
 require 'puppet/util/log_paths'
 require 'puppet/util/logging'
@@ -25,6 +24,143 @@ class Type
   include Puppet::FileCollection::Lookup
   include Puppet::Util::Tagging
 
+  ###
+  # This was all in metatype/manager.rb, for no real reason.
+  include Puppet::Util::ClassGen
+
+  # remove all type instances; this is mostly only useful for testing
+  def self.allclear
+    @types.each { |name, type|
+      type.clear
+    }
+  end
+
+  # iterate across all of the subclasses of Type
+  def self.eachtype
+    @types.each do |name, type|
+      yield type
+    end
+  end
+
+  # Load all types.  Only currently used for documentation.
+  def self.loadall
+    typeloader.loadall
+  end
+
+  # Define a new type.
+  def self.newtype(name, options = {}, &block)
+    # Handle backward compatibility
+    unless options.is_a?(Hash)
+      Puppet.warning "Puppet::Type.newtype(#{name}) now expects a hash as the 
second argument, not #{options.inspect}"
+      options = {:parent => options}
+    end
+
+    # First make sure we don't have a method sitting around
+    name = symbolize(name)
+    newmethod = "new#{name.to_s}"
+
+    # Used for method manipulation.
+    selfobj = singleton_class
+
+    @types ||= {}
+
+    if @types.include?(name)
+      if self.respond_to?(newmethod)
+        # Remove the old newmethod
+        selfobj.send(:remove_method,newmethod)
+      end
+    end
+
+    options = symbolize_options(options)
+
+    if parent = options[:parent]
+      options.delete(:parent)
+    end
+
+    # Then create the class.
+
+    klass = genclass(
+      name,
+      :parent => (parent || Puppet::Type),
+      :overwrite => true,
+      :hash => @types,
+      :attributes => options,
+      &block
+    )
+
+    # Now define a "new<type>" method for convenience.
+    if self.respond_to? newmethod
+      # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
+      Puppet.warning "'new#{name.to_s}' method already exists; skipping"
+    else
+      selfobj.send(:define_method, newmethod) do |*args|
+        klass.new(*args)
+      end
+    end
+
+    # If they've got all the necessary methods defined and they haven't
+    # already added the property, then do so now.
+    klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure)
+
+    # Now set up autoload any providers that might exist for this type.
+
+    klass.providerloader = Puppet::Util::Autoload.new(
+      klass,
+      "puppet/provider/#{klass.name.to_s}"
+    )
+
+    # This can only happen when the type is reloaded in memory and the 
providers
+    # are still there
+    unless klass.provider_hash.empty?
+      klass.providify
+    end
+
+    # We have to load everything so that we can figure out the default type.
+    klass.providerloader.loadall
+
+    klass
+  end
+
+  # Remove an existing defined type.  Largely used for testing.
+  def self.rmtype(name)
+
+    klass = rmclass(
+      name,
+      :hash => @types
+    )
+
+    singleton_class.send(:remove_method, "new#{name}") if 
respond_to?("new#{name}")
+  end
+
+  # Return a Type instance by name.
+  def self.type(name)
+    @types ||= {}
+
+    name = name.to_s.downcase.to_sym
+
+    if t = @types[name]
+      return t
+    else
+      if typeloader.load(name)
+        Puppet.warning "Loaded puppet/type/#{name} but no class was created" 
unless @types.include? name
+      end
+
+      return @types[name]
+    end
+  end
+
+  # Create a loader for Puppet types.
+  def self.typeloader
+    unless defined?(@typeloader)
+      @typeloader = Puppet::Util::Autoload.new(
+        self,
+        "puppet/type", :wrap => false
+      )
+    end
+
+    @typeloader
+  end
+
   ###############################
   # Code related to resource type attributes.
   class << self
@@ -33,11 +169,6 @@ class Type
     attr_reader :properties
   end
 
-  def self.states
-    warnonce "The states method is deprecated; use properties"
-    properties
-  end
-
   # All parameters, in the appropriate order.  The key_attributes come first, 
then
   # the provider, then the properties, and finally the params and metaparams
   # in the order they were specified in the files.
@@ -249,11 +380,6 @@ class Type
     param
   end
 
-  def self.newstate(name, options = {}, &block)
-    Puppet.warning "newstate() has been deprecrated; use newproperty(#{name})"
-    newproperty(name, options, &block)
-  end
-
   # Create a new property. The first parameter must be the name of the 
property;
   # this is how users will refer to the property when creating new instances.
   # The second parameter is a hash of options; the options are:
@@ -374,16 +500,6 @@ class Type
     obj = @parameters[:ensure] and obj.should == :absent
   end
 
-  # Create a new property if it is valid but doesn't exist
-  # Returns: true if a new parameter was added, false otherwise
-  def add_property_parameter(prop_name)
-    if self.class.validproperty?(prop_name) && !@parameters[prop_name]
-      self.newattr(prop_name)
-      return true
-    end
-    false
-  end
-
   #
   # The name_var is the key_attribute in the case that there is only one.
   #
@@ -764,111 +880,6 @@ class Type
   # Code related to managing resource instances.
   require 'puppet/transportable'
 
-  # retrieve a named instance of the current type
-  def self.[](name)
-    raise "Global resource access is deprecated"
-    @objects[name] || @aliases[name]
-  end
-
-  # add an instance by name to the class list of instances
-  def self.[]=(name,object)
-    raise "Global resource storage is deprecated"
-    newobj = nil
-    if object.is_a?(Puppet::Type)
-      newobj = object
-    else
-      raise Puppet::DevError, "must pass a Puppet::Type object"
-    end
-
-    if exobj = @objects[name] and self.isomorphic?
-      msg = "Object '#{newobj.class.name}[#{name}]' already exists"
-
-      msg += ("in file #{object.file} at line #{object.line}") if exobj.file 
and exobj.line
-      msg += ("and cannot be redefined in file #{object.file} at line 
#{object.line}") if object.file and object.line
-      error = Puppet::Error.new(msg)
-      raise error
-    else
-      #Puppet.info("adding %s of type %s to class list" %
-      #    [name,object.class])
-      @objects[name] = newobj
-    end
-  end
-
-  # Create an alias.  We keep these in a separate hash so that we don't 
encounter
-  # the objects multiple times when iterating over them.
-  def self.alias(name, obj)
-    raise "Global resource aliasing is deprecated"
-    if @objects.include?(name)
-      unless @objects[name] == obj
-        raise Puppet::Error.new(
-          "Cannot create alias #{name}: object already exists"
-        )
-      end
-    end
-
-    if @aliases.include?(name)
-      unless @aliases[name] == obj
-        raise Puppet::Error.new(
-          "Object #{@aliases[name].name} already has alias #{name}"
-        )
-      end
-    end
-
-    @aliases[name] = obj
-  end
-
-  # remove all of the instances of a single type
-  def self.clear
-    raise "Global resource removal is deprecated"
-    if defined?(@objects)
-      @objects.each do |name, obj|
-        obj.remove(true)
-      end
-      @objects.clear
-    end
-    @aliases.clear if defined?(@aliases)
-  end
-
-  # Force users to call this, so that we can merge objects if
-  # necessary.
-  def self.create(args)
-    # LAK:DEP Deprecation notice added 12/17/2008
-    Puppet.warning "Puppet::Type.create is deprecated; use Puppet::Type.new"
-    new(args)
-  end
-
-  # remove a specified object
-  def self.delete(resource)
-    raise "Global resource removal is deprecated"
-    return unless defined?(@objects)
-    @objects.delete(resource.title) if @objects.include?(resource.title)
-    @aliases.delete(resource.title) if @aliases.include?(resource.title)
-    if @aliases.has_value?(resource)
-      names = []
-      @aliases.each do |name, otherres|
-        if otherres == resource
-          names << name
-        end
-      end
-      names.each { |name| @aliases.delete(name) }
-    end
-  end
-
-  # iterate across each of the type's instances
-  def self.each
-    raise "Global resource iteration is deprecated"
-    return unless defined?(@objects)
-    @objects.each { |name,instance|
-      yield instance
-    }
-  end
-
-  # does the type have an object with the given name?
-  def self.has_key?(name)
-    raise "Global resource access is deprecated"
-    @objects.has_key?(name)
-  end
-
   # Retrieve all known instances.  Either requires providers or must be 
overridden.
   def self.instances
     raise Puppet::DevError, "#{self.name} has no providers and has not 
overridden 'instances'" if provider_hash.empty?
@@ -1650,7 +1661,6 @@ class Type
     attr_reader :name
     attr_accessor :self_refresh
     include Enumerable, Puppet::Util::ClassGen
-    include Puppet::MetaType::Manager
 
     include Puppet::Util
     include Puppet::Util::Logging
diff --git a/spec/integration/type_spec.rb b/spec/integration/type_spec.rb
deleted file mode 100755
index 9fd1048..0000000
--- a/spec/integration/type_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-require 'puppet/type'
-
-describe Puppet::Type do
-  it "should not lose its provider list when it is reloaded" do
-    type = Puppet::Type.newtype(:integration_test) do
-      newparam(:name) {}
-    end
-
-    provider = type.provide(:myprovider) {}
-
-    # reload it
-    type = Puppet::Type.newtype(:integration_test) do
-      newparam(:name) {}
-    end
-
-    type.provider(:myprovider).should equal(provider)
-  end
-
-  it "should not lose its provider parameter when it is reloaded" do
-    type = Puppet::Type.newtype(:reload_test_type)
-
-    provider = type.provide(:test_provider)
-
-    # reload it
-    type = Puppet::Type.newtype(:reload_test_type)
-
-    type.parameters.should include(:provider)
-  end
-end
diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb
index 3829cfa..c1c36ef 100755
--- a/spec/unit/transaction_spec.rb
+++ b/spec/unit/transaction_spec.rb
@@ -354,7 +354,7 @@ describe Puppet::Transaction do
       @transaction = Puppet::Transaction.new(@catalog)
 
       # Have both a title and name
-      resource = Puppet::Type.type(:sshkey).create :title => "foo", :name => 
"bar", :type => :dsa, :key => "eh"
+      resource = Puppet::Type.type(:sshkey).new :title => "foo", :name => 
"bar", :type => :dsa, :key => "eh"
       @catalog.add_resource resource
 
       resource.provider.class.expects(:prefetch).with("bar" => resource)
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index bbdaec3..30c5511 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -646,4 +646,36 @@ describe Puppet::Type.metaparamclass(:audit) do
       res.uniqueness_key.should == [ nil, 'root', '/my/file']
     end
   end
+
+  describe "when being reloaded" do
+    it "should not lose its provider list when it is reloaded" do
+      type = Puppet::Type.newtype(:reload_with_providers) do
+        newparam(:name) {}
+      end
+
+      provider = type.provide(:myprovider) {}
+
+      # reload it
+      type = Puppet::Type.newtype(:reload_with_providers) do
+        newparam(:name) {}
+      end
+
+      type.provider(:myprovider).should equal(provider)
+    end
+
+    it "should not lose its provider parameter when it is reloaded" do
+      type = Puppet::Type.newtype(:reload_test_type) do
+        newparam(:name) {}
+      end
+
+      provider = type.provide(:test_provider)
+
+      # reload it
+      type = Puppet::Type.newtype(:reload_test_type) do
+        newparam(:name) {}
+      end
+
+      type.parameters.should include(:provider)
+    end
+  end
 end
diff --git a/test/ral/manager/manager.rb b/test/ral/manager/manager.rb
deleted file mode 100755
index 9c9449a..0000000
--- a/test/ral/manager/manager.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env ruby
-#
-#  Created by Luke A. Kanies on 2006-11-29.
-#  Copyright (c) 2006. All rights reserved.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
-
-require 'puppettest'
-
-class TestTypeManager < Test::Unit::TestCase
-  include PuppetTest
-
-  class FakeManager
-    extend Puppet::MetaType::Manager
-    def self.clear
-      @types = {}
-    end
-  end
-
-  def teardown
-    super
-    FakeManager.clear
-  end
-
-  # Make sure we can remove defined types
-  def test_rmtype
-    assert_nothing_raised {
-      FakeManager.newtype :testing do
-        newparam(:name, :namevar => true)
-      end
-    }
-    assert(FakeManager.type(:testing), "Did not get fake type")
-
-    assert_nothing_raised do
-      FakeManager.rmtype(:testing)
-    end
-
-    assert_nil(FakeManager.type(:testing), "Type was not removed")
-    assert(! defined?(FakeManager::Testing), "Constant was not removed")
-  end
-
-  def test_newtype
-    assert_nothing_raised do
-      FakeManager.newtype(:testing, :self_refresh => true) do
-        newparam(:name, :namevar => true)
-      end
-    end
-
-    test = FakeManager.type(:testing)
-    assert(test, "did not get type")
-    assert(test.self_refresh, "did not set attribute")
-  end
-end
-
-- 
1.7.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to