]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/staging/lib/puppet/parser/functions/scope_defaults.rb
add nanliu/staging to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / staging / lib / puppet / parser / functions / scope_defaults.rb
diff --git a/3rdparty/modules/staging/lib/puppet/parser/functions/scope_defaults.rb b/3rdparty/modules/staging/lib/puppet/parser/functions/scope_defaults.rb
new file mode 100644 (file)
index 0000000..6c81484
--- /dev/null
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+  newfunction(:scope_defaults, :type => :rvalue, :doc => <<-EOS
+Determine if specified resource defaults have a attribute defined in
+current scope.
+EOS
+  ) do |arguments|
+
+    raise(Puppet::ParseError, "scope_defaults(): Wrong number of arguments " +
+      "given (#{arguments.size} for 2)") if arguments.size != 2
+
+    # auto capitalize puppet resource for lookup:
+    res_type = arguments[0].split('::').collect{ |x| x.capitalize }.join('::')
+    res_attr = arguments[1]
+
+    return self.lookupdefaults(res_type).has_key?(res_attr.to_sym)
+  end
+end