diff options
author | Luke Kanies <luke@reductivelabs.com> | 2010-01-30 23:51:59 -0600 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 5401a7ca8550ade0443188b505a104ca5726ec80 (patch) | |
tree | 137027c51dfd95c1c5cd0c53a4d5361e8fe46576 /lib/puppet/resource.rb | |
parent | 9c867e6d79dcc56cd34683c9a339dc729ad2d291 (diff) | |
download | puppet-5401a7ca8550ade0443188b505a104ca5726ec80.tar.gz puppet-5401a7ca8550ade0443188b505a104ca5726ec80.tar.xz puppet-5401a7ca8550ade0443188b505a104ca5726ec80.zip |
Adding strictness checking to resources
This is used for AST resources (and fixed the last
of the tests I broke in spec/).
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/resource.rb')
-rw-r--r-- | lib/puppet/resource.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 630e8a823..e29fecf45 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -12,7 +12,7 @@ class Puppet::Resource extend Puppet::Util::Pson include Enumerable - attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters + attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters, :strict attr_reader :title, :namespaces attr_writer :relative_type @@ -138,7 +138,7 @@ class Puppet::Resource end end - %w{exported virtual}.each do |m| + %w{exported virtual strict}.each do |m| define_method(m+"?") do self.send(m) end @@ -149,10 +149,7 @@ class Puppet::Resource @parameters = {} @namespaces = [""] - (attributes[:parameters] || {}).each do |param, value| - self[param] = value - end - + # Set things like namespaces and strictness first. attributes.each do |attr, value| next if attr == :parameters send(attr.to_s + "=", value) @@ -165,8 +162,17 @@ class Puppet::Resource self.type = tmp_type self.title = tmp_title + (attributes[:parameters] || {}).each do |param, value| + validate_parameter(param) if strict? + self[param] = value + end + tag(self.type) tag(self.title) if valid_tag?(self.title) + + if strict? and ! resource_type + raise ArgumentError, "Invalid resource type #{type}" + end end def ref |