diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-03-25 11:28:13 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-03-25 14:31:27 -0700 |
| commit | da082d500e1f1192dbc987483d753d93b5698094 (patch) | |
| tree | 7ea0886f5d12c29ad653224e8eed68edbf99abbd | |
| parent | 4196699f5fbb90ceecbb709c8502622eaad39062 (diff) | |
| download | puppet-da082d500e1f1192dbc987483d753d93b5698094.tar.gz puppet-da082d500e1f1192dbc987483d753d93b5698094.tar.xz puppet-da082d500e1f1192dbc987483d753d93b5698094.zip | |
Fixed #6850 - Clean up ResourceType#to_pson
There's no value in including the code when we convert a resource
type to JSON, since you can't convert it back again, so this removes
it.
I also cleaned up a few of the other attributes which were
producing unnecessary information.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
| -rw-r--r-- | lib/puppet/indirector/resource_type/parser.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/resource/type.rb | 6 | ||||
| -rwxr-xr-x | spec/unit/resource/type_spec.rb | 22 |
3 files changed, 27 insertions, 8 deletions
diff --git a/lib/puppet/indirector/resource_type/parser.rb b/lib/puppet/indirector/resource_type/parser.rb index 8b1bed0a9..24b4b065e 100644 --- a/lib/puppet/indirector/resource_type/parser.rb +++ b/lib/puppet/indirector/resource_type/parser.rb @@ -18,6 +18,13 @@ class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code end def search(request) +=begin + @modulepath = set_modulepath(options[:modulepath]) + get_code(@modulepath)[:manifests].collect do |file| + Puppet[:manifest]=file + get_resources_of_type(:hostclass) + end.flatten +=end raise ArgumentError, "Only '*' is acceptable as a search request" unless request.key == "*" krt = request.environment.known_resource_types result = [krt.hostclasses.values, krt.definitions.values, krt.nodes.values].flatten diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index b9cf6991a..48d8c1f48 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -34,13 +34,13 @@ class Puppet::Resource::Type end def to_pson_data_hash - data = [:code, :doc, :line, :file, :parent].inject({}) do |hash, param| - next hash unless value = self.send(param) + data = [:doc, :line, :file, :parent].inject({}) do |hash, param| + next hash unless (value = self.send(param)) and (value != "") hash[param.to_s] = value hash end - data['arguments'] = arguments.dup + data['arguments'] = arguments.dup unless arguments.empty? data['name'] = name data['type'] = type diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index e9c203526..41b5554d9 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -55,12 +55,24 @@ describe Puppet::Resource::Type do double_convert.arguments.should == {"one" => nil, "two" => "foo"} end - it "should include any extra attributes" do - @type.file = "/my/file" - @type.line = 50 + it "should not include arguments if none are present" do + @type.to_pson["arguments"].should be_nil + end + + [:line, :doc, :file, :parent].each do |attr| + it "should include #{attr} when set" do + @type.send(attr.to_s + "=", "value") + double_convert.send(attr).should == "value" + end + + it "should not include #{attr} when not set" do + @type.to_pson[attr.to_s].should be_nil + end + end - double_convert.file.should == "/my/file" - double_convert.line.should == 50 + it "should not include docs if they are empty" do + @type.doc = "" + @type.to_pson["doc"].should be_nil end end |
