summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-04 18:24:24 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-10-04 18:24:24 +0000
commit28cee40689440388994a4768bd301ae32c8ecc05 (patch)
treec865ab44f4c9247052cf83de16ffc8ebe8b15e54 /lib/puppet/parser/resource
parente0e291332bd4676962a28c7b220ae5c5e9651c0a (diff)
downloadpuppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.gz
puppet-28cee40689440388994a4768bd301ae32c8ecc05.tar.xz
puppet-28cee40689440388994a4768bd301ae32c8ecc05.zip
Merging the changes from the override-refactor branch. This is a significant rewrite of the parser, but it has little affect on the rest of the code tree.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1726 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/resource')
-rw-r--r--lib/puppet/parser/resource/param.rb44
-rw-r--r--lib/puppet/parser/resource/reference.rb68
2 files changed, 112 insertions, 0 deletions
diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb
new file mode 100644
index 000000000..259e935d1
--- /dev/null
+++ b/lib/puppet/parser/resource/param.rb
@@ -0,0 +1,44 @@
+# The parameters we stick in Resources.
+class Puppet::Parser::Resource::Param
+ attr_accessor :name, :value, :source, :line, :file
+ include Puppet::Util::Errors
+ include Puppet::Util::MethodHelper
+
+ def initialize(hash)
+ set_options(hash)
+ requiredopts(:name, :value, :source)
+ @name = @name.intern if @name.is_a?(String)
+ end
+
+ def inspect
+ "#<#{self.class} @name => #{self.name}, @value => #{self.value}, @source => #{self.source.type}>"
+ end
+
+ # Store this parameter in a Rails db.
+ def store(resource)
+ args = {}
+ [:name, :value, :line, :file].each do |var|
+ if val = self.send(var)
+ args[var] = val
+ end
+ end
+ args[:name] = args[:name].to_s
+ if obj = resource.rails_parameters.find_by_name(self.name)
+ # We exist
+ args.each do |p, v|
+ obj[p] = v
+ end
+ else
+ # Else create it anew
+ obj = resource.rails_parameters.build(args)
+ end
+
+ return obj
+ end
+
+ def to_s
+ "%s => %s" % [self.name, self.value]
+ end
+end
+
+# $Id$
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
new file mode 100644
index 000000000..2210b71c2
--- /dev/null
+++ b/lib/puppet/parser/resource/reference.rb
@@ -0,0 +1,68 @@
+# A reference to a resource. Mostly just the type and title.
+class Puppet::Parser::Resource::Reference
+ include Puppet::Util::MethodHelper
+ include Puppet::Util::Errors
+
+ attr_accessor :type, :title, :builtin, :file, :line, :scope
+
+ # Are we a builtin type?
+ def builtin?
+ unless defined? @builtin
+ if builtintype()
+ @builtin = true
+ else
+ @builtin = false
+ end
+ end
+
+ self.builtin
+ end
+
+ def builtintype
+ if t = Puppet::Type.type(self.type) and t.name != :component
+ t
+ else
+ nil
+ end
+ end
+
+ # Return the defined type for our obj.
+ def definedtype
+ unless defined? @definedtype
+ if tmp = @scope.finddefine(self.type)
+ @definedtype = tmp
+ else
+ fail Puppet::ParseError, "Could not find definition %s" % self.type
+ end
+ end
+
+ @definedtype
+ end
+
+ def initialize(hash)
+ set_options(hash)
+ requiredopts(:type, :title)
+ end
+
+ def to_ref
+ return [type.to_s,title.to_s]
+ end
+
+ def to_s
+ "%s[%s]" % [type, title]
+ end
+
+ def typeclass
+ unless defined? @typeclass
+ if tmp = builtintype || definedtype
+ @typeclass = tmp
+ else
+ fail Puppet::ParseError, "Could not find type %s" % self.type
+ end
+ end
+
+ @typeclass
+ end
+end
+
+# $Id$