diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/functions/deprecation.rb | 6 | ||||
-rw-r--r-- | lib/puppet/functions/type_of.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/functions/deprecation.rb | 4 | ||||
-rw-r--r-- | lib/puppet/parser/functions/ensure_resources.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/functions/join_keys_to_values.rb | 15 |
5 files changed, 23 insertions, 6 deletions
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb index a860aa2..39d9bc7 100644 --- a/lib/puppet/functions/deprecation.rb +++ b/lib/puppet/functions/deprecation.rb @@ -8,6 +8,12 @@ Puppet::Functions.create_function(:deprecation) do end def deprecation(key, message) + if defined? Puppet::Pops::PuppetStack.stacktrace() + stacktrace = Puppet::Pops::PuppetStack.stacktrace() + file = stacktrace[0] + line = stacktrace[1] + message = "#{message} at #{file}:#{line}" + end # depending on configuration setting of strict case Puppet.settings[:strict] when :off diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb index 02cdd4d..01f1f49 100644 --- a/lib/puppet/functions/type_of.rb +++ b/lib/puppet/functions/type_of.rb @@ -10,6 +10,8 @@ # See the documentation for "The Puppet Type System" for more information about types. # See the `assert_type()` function for flexible ways to assert the type of a value. # +# The built-in type() function in puppet is generally preferred over this function +# this function is provided for backwards compatibility. Puppet::Functions.create_function(:type_of) do def type_of(value) Puppet::Pops::Types::TypeCalculator.infer_set(value) diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb index e30f3a0..cd64fe2 100644 --- a/lib/puppet/parser/functions/deprecation.rb +++ b/lib/puppet/parser/functions/deprecation.rb @@ -1,5 +1,5 @@ module Puppet::Parser::Functions - newfunction(:deprecation, :type => :rvalue, :doc => <<-EOS + newfunction(:deprecation, :doc => <<-EOS Function to print deprecation warnings (this is the 3.X version of it), The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method.). EOS ) do |arguments| @@ -9,7 +9,7 @@ EOS key = arguments[0] message = arguments[1] - + if ENV['STDLIB_LOG_DEPRECATIONS'] == "true" warning("deprecation. #{key}. #{message}") end diff --git a/lib/puppet/parser/functions/ensure_resources.rb b/lib/puppet/parser/functions/ensure_resources.rb index 30d57a8..b3c51e6 100644 --- a/lib/puppet/parser/functions/ensure_resources.rb +++ b/lib/puppet/parser/functions/ensure_resources.rb @@ -36,7 +36,7 @@ ENDOFDOC params ||= {} if title.is_a?(Hash) - resource_hash = Hash(title) + resource_hash = title.dup resources = resource_hash.keys Puppet::Parser::Functions.function(:ensure_resource) diff --git a/lib/puppet/parser/functions/join_keys_to_values.rb b/lib/puppet/parser/functions/join_keys_to_values.rb index e9924fe..e3baf9f 100644 --- a/lib/puppet/parser/functions/join_keys_to_values.rb +++ b/lib/puppet/parser/functions/join_keys_to_values.rb @@ -5,7 +5,8 @@ module Puppet::Parser::Functions newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS This function joins each key of a hash to that key's corresponding value with a -separator. Keys and values are cast to strings. The return value is an array in +separator. Keys are cast to strings. If values are arrays, multiple keys +are added for each element. The return value is an array in which each element is one joined key/value pair. *Examples:* @@ -13,6 +14,10 @@ which each element is one joined key/value pair. join_keys_to_values({'a'=>1,'b'=>2}, " is ") Would result in: ["a is 1","b is 2"] + + join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ") + +Would result in: ["a is 1","b is 2","b is 3"] EOS ) do |arguments| @@ -38,8 +43,12 @@ Would result in: ["a is 1","b is 2"] # Join the keys to their values. hash.map do |k,v| - String(k) + separator + String(v) - end + if v.is_a?(Array) + v.map { |va| String(k) + separator + String(va) } + else + String(k) + separator + String(v) + end + end.flatten end end |