From 7089446697ad550c22012bc2b5572030727d67e1 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 29 Jan 2010 20:57:21 -0600 Subject: Removing Resource::Reference classes This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies --- lib/puppet/parser/functions/defined.rb | 6 +++--- lib/puppet/parser/functions/require.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/defined.rb b/lib/puppet/parser/functions/defined.rb index 5ad74a79e..4d1d8c6fd 100644 --- a/lib/puppet/parser/functions/defined.rb +++ b/lib/puppet/parser/functions/defined.rb @@ -6,21 +6,21 @@ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Dete (e.g., ``if defined(File['/tmp/myfile']) { ... }``). This function is unfortunately dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals| result = false + vals = [vals] unless vals.is_a?(Array) vals.each do |val| case val when String - # For some reason, it doesn't want me to return from here. if Puppet::Type.type(val) or find_definition(val) or find_hostclass(val) result = true break end - when Puppet::Parser::Resource::Reference + when Puppet::Resource if findresource(val.to_s) result = true break end else - raise ArgumentError, "Invalid argument of type %s to 'defined'" % val.class + raise ArgumentError, "Invalid argument of type '#{val.class}' to 'defined'" end end result diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb index 66d60b9ce..294484a2b 100644 --- a/lib/puppet/parser/functions/require.rb +++ b/lib/puppet/parser/functions/require.rb @@ -49,7 +49,7 @@ fail if used with earlier clients. # The 'obvious' way is just to add an edge in the catalog, # but that is considered a containment edge, not a dependency # edge, so it usually gets lost on the client. - ref = Puppet::Parser::Resource::Reference.new(:type => :class, :title => klass) + ref = Puppet::Resource.new(:class, klass) resource.set_parameter(:require, [resource[:require]].flatten.compact << ref) end end -- cgit