summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/resource_override.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-06 18:53:00 -0500
committerLuke Kanies <luke@madstop.com>2007-09-06 18:53:00 -0500
commitb7f42441b91c921cd31f3d8c7875ce98bdedf786 (patch)
tree07ef5bf2d42027914704d0305a353741d191cc90 /lib/puppet/parser/ast/resource_override.rb
parent653c1514b613f27cb22d24b4bdd7b6c118047566 (diff)
downloadpuppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.tar.gz
puppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.tar.xz
puppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.zip
Renaming some ast resource classes and files so they make a lot more sense.
Diffstat (limited to 'lib/puppet/parser/ast/resource_override.rb')
-rw-r--r--lib/puppet/parser/ast/resource_override.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
new file mode 100644
index 000000000..46c930902
--- /dev/null
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -0,0 +1,60 @@
+require 'puppet/parser/ast/resource'
+
+class Puppet::Parser::AST
+ # Set a parameter on a resource specification created somewhere else in the
+ # configuration. The object is responsible for verifying that this is allowed.
+ class ResourceOverride < Resource
+ attr_accessor :object
+ attr_reader :params
+
+ # Iterate across all of our children.
+ def each
+ [@object,@params].flatten.each { |param|
+ #Puppet.debug("yielding param %s" % param)
+ yield param
+ }
+ end
+
+ # Does not actually return an object; instead sets an object
+ # in the current scope.
+ def evaluate(hash)
+ scope = hash[:scope]
+
+ # Get our object reference.
+ object = @object.safeevaluate(:scope => scope)
+
+ hash = {}
+
+ # Evaluate all of the specified params.
+ params = @params.collect { |param|
+ param.safeevaluate(:scope => scope)
+ }
+
+ # Now we just create a normal resource, but we call a very different
+ # method on the scope.
+ obj = Puppet::Parser::Resource.new(
+ :type => object.type,
+ :title => object.title,
+ :params => params,
+ :file => @file,
+ :line => @line,
+ :source => scope.source,
+ :scope => scope
+ )
+
+ # Now we tell the scope that it's an override, and it behaves as
+ # necessary.
+ scope.compile.store_override(obj)
+
+ obj
+ end
+
+ # Create our ResourceDef. Handles type checking for us.
+ def initialize(hash)
+ @checked = false
+ super
+
+ #self.typecheck(@type.value)
+ end
+ end
+end