Replaced with Puppet::Type.valid_parameter?

Signed-off-by: Luke Kanies <[email protected]>
---
Local-branch: refactor/master/8233-refactor_parameter_management
 lib/puppet/provider/ldap.rb        |    6 +++---
 lib/puppet/type.rb                 |   27 ++++++++++++---------------
 lib/puppet/type/cron.rb            |    1 -
 lib/puppet/type/resources.rb       |    4 ++--
 spec/unit/provider/ldap_spec.rb    |    8 ++++----
 spec/unit/type/nagios_spec.rb      |    8 ++++----
 spec/unit/type_spec.rb             |    7 +++++++
 test/lib/puppettest/fakes.rb       |    8 --------
 test/ral/providers/user/useradd.rb |    4 ++--
 9 files changed, 34 insertions(+), 39 deletions(-)

diff --git a/lib/puppet/provider/ldap.rb b/lib/puppet/provider/ldap.rb
index becb753..3717932 100644
--- a/lib/puppet/provider/ldap.rb
+++ b/lib/puppet/provider/ldap.rb
@@ -44,9 +44,9 @@ class Puppet::Provider::Ldap < Puppet::Provider
 
   def create
     @property_hash[:ensure] = :present
-    self.class.resource_type.validproperties.each do |property|
-      if val = resource.should(property)
-        @property_hash[property] = val
+    self.class.resource_type.properties.each do |property|
+      if val = resource[property.name]
+        @property_hash[property.name] = val
       end
     end
   end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index c318568..96a069d 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -100,7 +100,7 @@ class Type
 
     # 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)
+    klass.ensurable if klass.ensurable? and ! klass.valid_parameter?(:ensure)
 
     # Now set up autoload any providers that might exist for this type.
 
@@ -240,6 +240,11 @@ class Type
     klass.parameter_type
   end
 
+  # Return all of the properties this resource type supports.
+  def self.properties
+    parameters.find_all { |p| p.property? }
+  end
+
   # Is the provided name a valid parameter?
   # This method is used in both Puppet::Type and Puppet::Resource.
   def self.valid_parameter?(name)
@@ -270,15 +275,7 @@ class Type
   # 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.
-  def self.properties
-    parameters.find_all { |p| p.property? }
-  end
-
   # does the name reflect a valid property?
-  def self.validproperty?(name)
-    p = parameter(name) and p.property?
-  end
-
   # Return the list of validproperties
   def self.validproperties
     parameters.find_all { |p| p.property? }.collect { |p| p.name }
@@ -989,7 +986,6 @@ class Type
 
     munge do |args|
       properties_to_audit(args).each do |param|
-        next unless resource.class.validproperty?(param)
         resource.newattr(param)
       end
     end
@@ -1003,10 +999,13 @@ class Type
     end
 
     def properties_to_audit(list)
+      all = all_properties
       if !list.kind_of?(Array) && list.to_sym == :all
-        list = all_properties
+        all
       else
-        list = Array(list).collect { |p| p.to_sym }
+        # Any parameters that are specified and also fall into the
+        # 'all properties' list.
+        (Array(list).collect { |p| p.to_sym } & all)
       end
     end
   end
@@ -1819,9 +1818,7 @@ class Type
   def title
     unless @title
       if self.class.valid_parameter?(name_var)
-        @title = self[:name]
-      elsif self.class.validproperty?(name_var)
-        @title = self.should(name_var)
+        @title = self[name_var]
       else
         self.devfail "Could not find namevar #{name_var} for 
#{self.class.name}"
       end
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 5083ca5..b38bb4c 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -399,7 +399,6 @@ Puppet::Type.newtype(:cron) do
       when :special
         # nothing
       else
-        #ret = (self.class.validproperty?(name).default || "*").to_s
         ret = "*"
       end
     end
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index ff3c07f..483f5b3 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -29,7 +29,7 @@ Puppet::Type.newtype(:resources) do
         unless @resource.resource_type.respond_to?(:instances)
           raise ArgumentError, "Purging resources of type #{@resource[:name]} 
is not supported, since they cannot be queried from the system"
         end
-        raise ArgumentError, "Purging is only supported on types that accept 
'ensure'" unless @resource.resource_type.validproperty?(:ensure)
+        raise ArgumentError, "Purging is only supported on types that accept 
'ensure'" unless @resource.resource_type.valid_parameter?(:ensure)
       end
     end
   end
@@ -88,7 +88,7 @@ Puppet::Type.newtype(:resources) do
     resource_type.instances.
       reject { |r| catalog.resource_refs.include? r.ref }.
       select { |r| check(r) }.
-      select { |r| r.class.validproperty?(:ensure) }.
+      select { |r| r.class.valid_parameter?(:ensure) }.
       select { |r| able_to_ensure_absent?(r) }.
       each { |resource|
         @parameters.each do |name, param|
diff --git a/spec/unit/provider/ldap_spec.rb b/spec/unit/provider/ldap_spec.rb
index 597a412..44c9dc9 100755
--- a/spec/unit/provider/ldap_spec.rb
+++ b/spec/unit/provider/ldap_spec.rb
@@ -177,7 +177,7 @@ describe Puppet::Provider::Ldap do
       @instance = @class.new
 
       @property_class = stub 'property_class', :array_matching => :all, 
:superclass => Puppet::Property
-      @resource_class = stub 'resource_class', :parameter => @property_class, 
:valid_parameter? => true, :validproperties => [:one, :two]
+      @resource_class = stub 'resource_class', :parameter => @property_class, 
:valid_parameter? => true, :properties => [stub(:name => :one), stub(:name => 
:two)]
       @class.stubs(:resource_type).returns @resource_class
     end
 
@@ -219,7 +219,7 @@ describe Puppet::Provider::Ldap do
         @rclass.stubs(:validproperties).returns([:one, :two])
         @resource = mock 'resource'
         @resource.stubs(:class).returns @rclass
-        @resource.stubs(:should).returns nil
+        @resource.stubs(:[]).returns nil
         @instance.stubs(:resource).returns @resource
       end
 
@@ -229,8 +229,8 @@ describe Puppet::Provider::Ldap do
       end
 
       it "should set all of the other attributes from the resource" do
-        @resource.expects(:should).with(:one).returns "oneval"
-        @resource.expects(:should).with(:two).returns "twoval"
+        @resource.expects(:[]).with(:one).returns "oneval"
+        @resource.expects(:[]).with(:two).returns "twoval"
 
         @instance.create
         @instance.properties[:one].should == "oneval"
diff --git a/spec/unit/type/nagios_spec.rb b/spec/unit/type/nagios_spec.rb
index eafc00c..5758f97 100755
--- a/spec/unit/type/nagios_spec.rb
+++ b/spec/unit/type/nagios_spec.rb
@@ -31,11 +31,11 @@ describe "Nagios resource types" do
       end
 
       it "should have an ensure property" do
-        puppet_type.should be_validproperty(:ensure)
+        puppet_type.should be_valid_parameter(:ensure)
       end
 
       it "should have a target property" do
-        puppet_type.should be_validproperty(:target)
+        puppet_type.should be_valid_parameter(:target)
       end
 
       it "should have documentation for its target property" do
@@ -44,7 +44,7 @@ describe "Nagios resource types" do
 
       nagios_type.parameters.reject { |param| param == nagios_type.namevar or 
param.to_s =~ /^[0-9]/ }.each do |param|
         it "should have a #{param} property" do
-          puppet_type.should be_validproperty(param)
+          puppet_type.should be_valid_parameter(param)
         end
 
         it "should have documentation for its #{param} property" do
@@ -54,7 +54,7 @@ describe "Nagios resource types" do
 
       nagios_type.parameters.find_all { |param| param.to_s =~ /^[0-9]/ }.each 
do |param|
         it "should have not have a #{param} property" do
-          puppet_type.should_not be_validproperty(:param)
+          puppet_type.should_not be_valid_parameter(:param)
         end
       end
     end
diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
index e0897f0..eb7e595 100755
--- a/spec/unit/type_spec.rb
+++ b/spec/unit/type_spec.rb
@@ -269,6 +269,13 @@ describe Puppet::Type do
     it "should not consider :name to be a valid metaparameter" do
       Puppet::Type.should_not be_metaparameter(:name)
     end
+
+    it "should be able to return all known properties" do
+      foo = @type.newproperty(:foo)
+      bar = @type.newproperty(:bar)
+
+      @type.properties.should == [foo, bar]
+    end
   end
 
   describe "when creating an event" do
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index 40ec549..91d5da2 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -13,14 +13,6 @@ module PuppetTest
       @realresource.key_attributes
     end
 
-    def self.validproperties
-      Puppet::Type.type(@name).validproperties
-    end
-
-    def self.validproperty?(name)
-      Puppet::Type.type(@name).validproperty?(name)
-    end
-
     def self.to_s
       "Fake#{@name.to_s.capitalize}"
     end
diff --git a/test/ral/providers/user/useradd.rb 
b/test/ral/providers/user/useradd.rb
index 6350ec6..dbb9fed 100755
--- a/test/ral/providers/user/useradd.rb
+++ b/test/ral/providers/user/useradd.rb
@@ -28,7 +28,7 @@ class UserAddProviderTest < PuppetTest::TestCase
     @user = @type.new(@vals)
 
     @vals.each do |name, val|
-      next unless @user.class.validproperty?(name)
+      next unless @user.class.valid_parameter?(name)
     end
     @user
   end
@@ -47,7 +47,7 @@ class UserAddProviderTest < PuppetTest::TestCase
     user = setup_user
 
     @vals.each do |name, val|
-      next unless user.class.validproperty?(name)
+      next unless user.class.valid_parameter?(name)
     end
 
     user.expects(:allowdupe?).returns(false)
-- 
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