We need the ability to set the namespace and
environment at initialization so the resource
can look up qualified types.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/resource.rb            |   12 +++++++++---
 lib/puppet/transportable.rb       |    2 +-
 lib/puppet/util/settings.rb       |    4 ++--
 spec/integration/util/settings.rb |    4 ++--
 spec/unit/resource.rb             |   25 ++++++++++++++++++++-----
 spec/unit/type.rb                 |    8 ++++----
 6 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 91dd547..ab03bfd 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -108,14 +108,20 @@ class Puppet::Resource
     end
 
     # Create our resource.
-    def initialize(type, title, parameters = {})
-        @reference = Puppet::Resource::Reference.new(type, title)
+    def initialize(type, title, attributes = {})
         @parameters = {}
 
-        parameters.each do |param, value|
+        (attributes[:parameters] || {}).each do |param, value|
             self[param] = value
         end
 
+        attributes.each do |attr, value|
+            next if attr == :parameters
+            send(attr.to_s + "=", value)
+        end
+
+        @reference = Puppet::Resource::Reference.new(type, title)
+
         tag(@reference.type)
         tag(@reference.title) if valid_tag?(@reference.title)
     end
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 85a75d4..68977dc 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -80,7 +80,7 @@ module Puppet
 
         # Create a normalized resource from our TransObject.
         def to_resource
-            result = Puppet::Resource.new(type, name, @params.dup)
+            result = Puppet::Resource.new(type, name, :parameters => 
@params.dup)
             result.tag(*tags)
 
             result
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index e6e1333..a05d85b 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -814,14 +814,14 @@ Generated on #{Time.now}.
             next unless sections.nil? or sections.include?(setting.section)
 
             if user = setting.owner and user != "root" and 
catalog.resource(:user, user).nil?
-                resource = Puppet::Resource.new(:user, user, :ensure => 
:present)
+                resource = Puppet::Resource.new(:user, user, :parameters => 
{:ensure => :present})
                 if self[:group]
                     resource[:gid] = self[:group]
                 end
                 catalog.add_resource resource
             end
             if group = setting.group and ! %w{root wheel}.include?(group) and 
catalog.resource(:group, group).nil?
-                catalog.add_resource Puppet::Resource.new(:group, group, 
:ensure => :present)
+                catalog.add_resource Puppet::Resource.new(:group, group, 
:parameters => {:ensure => :present})
             end
         end
     end
diff --git a/spec/integration/util/settings.rb 
b/spec/integration/util/settings.rb
index 146b988..faab9db 100755
--- a/spec/integration/util/settings.rb
+++ b/spec/integration/util/settings.rb
@@ -9,7 +9,7 @@ describe Puppet::Util::Settings do
 
     it "should be able to make needed directories" do
         settings = Puppet::Util::Settings.new
-        settings.setdefaults :main, :maindir => [tmpfile("main"), "a"]
+        settings.setdefaults :main, :maindir => [tmpfile("main"), "a"], :noop 
=> [false, "meh"]
 
         settings.use(:main)
 
@@ -18,7 +18,7 @@ describe Puppet::Util::Settings do
 
     it "should make its directories with the corret modes" do
         settings = Puppet::Util::Settings.new
-        settings.setdefaults :main, :maindir => {:default => tmpfile("main"), 
:desc => "a", :mode => 0750}
+        settings.setdefaults :main, :maindir => {:default => tmpfile("main"), 
:desc => "a", :mode => 0750}, :noop => [false, "meh"]
 
         settings.use(:main)
 
diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb
index b26f4f9..32b0017 100755
--- a/spec/unit/resource.rb
+++ b/spec/unit/resource.rb
@@ -23,10 +23,6 @@ describe Puppet::Resource do
             Puppet::Resource.new("file", "/f")
         end
 
-        it "should allow setting of parameters" do
-            Puppet::Resource.new("file", "/f", :noop => true)[:noop].should 
be_true
-        end
-
         it "should tag itself with its type" do
             Puppet::Resource.new("file", "/f").should be_tagged("file")
         end
@@ -38,6 +34,11 @@ describe Puppet::Resource do
         it "should not tag itself with its title if the title is a not valid 
tag" do
             Puppet::Resource.new("file", "/bar").should_not be_tagged("/bar")
         end
+
+        it "should allow setting of attributes" do
+            Puppet::Resource.new("file", "/bar", :file => "/foo").file.should 
== "/foo"
+            Puppet::Resource.new("file", "/bar", :exported => true).should 
be_exported
+        end
     end
 
     it "should use the resource reference to determine its type" do
@@ -89,16 +90,30 @@ describe Puppet::Resource do
         resource.should be_exported
     end
 
+    it "should support an environment attribute"
+
+    it "should convert its environment into an environment instance if one is 
provided"
+
+    it "should support a namespace attribute"
+
     describe "when managing parameters" do
         before do
             @resource = Puppet::Resource.new("file", "/my/file")
         end
 
+        it "should be able to check whether parameters are valid when the 
resource models builtin resources"
+
+        it "should be able to check whether parameters are valid when the 
resource models defined resources"
+
         it "should allow setting and retrieving of parameters" do
             @resource[:foo] = "bar"
             @resource[:foo].should == "bar"
         end
 
+        it "should allow setting of parameters at initialization" do
+            Puppet::Resource.new("file", "/my/file", :parameters => {:foo => 
"bar"})[:foo].should == "bar"
+        end
+
         it "should canonicalize retrieved parameter names to treat symbols and 
strings equivalently" do
             @resource[:foo] = "bar"
             @resource["foo"].should == "bar"
@@ -255,7 +270,7 @@ describe Puppet::Resource do
 
     describe "when converting to puppet code" do
         before do
-            @resource = Puppet::Resource.new("one::two", "/my/file", :noop => 
true, :foo => %w{one two})
+            @resource = Puppet::Resource.new("one::two", "/my/file", 
:parameters => {:noop => true, :foo => %w{one two}})
         end
 
         it "should print the type and title" do
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index 11bedaa..cfc061f 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -125,7 +125,7 @@ describe Puppet::Type do
 
         describe "and passed a Puppet::Resource instance" do
             it "should set its title to the title of the resource if the 
resource type is equal to the current type" do
-                resource = Puppet::Resource.new(:mount, "/foo", :name => 
"/other")
+                resource = Puppet::Resource.new(:mount, "/foo", :parameters => 
{:name => "/other"})
                 Puppet::Type.type(:mount).new(resource).title.should == "/foo"
             end
 
@@ -152,7 +152,7 @@ describe Puppet::Type do
             end
 
             it "should copy the resource's parameters as its own" do
-                resource = Puppet::Resource.new(:mount, "/foo", :atboot => 
true, :fstype => "boo")
+                resource = Puppet::Resource.new(:mount, "/foo", :parameters => 
{:atboot => true, :fstype => "boo"})
                 params = Puppet::Type.type(:mount).new(resource).to_hash
                 params[:fstype].should == "boo"
                 params[:atboot].should == true
@@ -214,7 +214,7 @@ describe Puppet::Type do
 
         it "should set the attributes in the order returned by the class's 
:allattrs method" do
             Puppet::Type.type(:mount).stubs(:allattrs).returns([:name, 
:atboot, :noop])
-            resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", 
:atboot => "myboot", :noop => "whatever")
+            resource = Puppet::Resource.new(:mount, "/foo", :parameters => 
{:name => "myname", :atboot => "myboot", :noop => "whatever"})
 
             set = []
 
@@ -231,7 +231,7 @@ describe Puppet::Type do
 
         it "should always set the name and then default provider before 
anything else" do
             Puppet::Type.type(:mount).stubs(:allattrs).returns([:provider, 
:name, :atboot])
-            resource = Puppet::Resource.new(:mount, "/foo", :name => "myname", 
:atboot => "myboot")
+            resource = Puppet::Resource.new(:mount, "/foo", :parameters => 
{:name => "myname", :atboot => "myboot"})
 
             set = []
 
-- 
1.6.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