Issue #15756 has been updated by Andrew  Parker.

>From what I understand a function should always be expecting an array. The 
>example that is given works in ruby 1.8 because `String` had an `#each` 
>method, whereas in ruby 1.9 `String` does not. The `#each` method was dropped 
>in favor of `#each_line` which is much more explicit about what it will be 
>iterating over, but also means that `String` is no longer `Enumerable`. So 
>`#function_template` just happened to work because the string being passed has 
>a single line that is the template to render.

In the end this really seems to be a documentation bug because the docs for 
writing functions state that the [brackets for creating an array are required 
at the call 
site](http://docs.puppetlabs.com/guides/custom_functions.html#referencing-custom-functions-in-templates).

Instead of opening us up to more complicated semantics around when to convert 
things to arrays, we should probably add an assertion to the function calling 
code to make sure that a single array is being passed. That would catch errors 
like this much earlier.
----------------------------------------
Bug #15756: scope.function_template with a single String parameter fails in 
Ruby 1.9
https://projects.puppetlabs.com/issues/15756#change-69514

Author: Roger Que
Status: Accepted
Priority: Normal
Assignee: eric sorenson
Category: templates
Target version: 3.0.0
Affected Puppet version: 2.7.18
Keywords: ruby19 functions
Branch: 


The Puppet documentation mentions [using `scope.function_template` with a 
String 
parameter](http://docs.puppetlabs.com/guides/templating.html#access-to-variables-and-puppet-functions-with-the-scope-object)
 in order to render an ERB template inside another template:

    <%= scope.function_template('referenced_template.erb') %>

This works in Ruby 1.8, but fails with the following error when the Puppet 
master is running 1.9:

    err: Could not retrieve catalog from remote server: Error 400 on SERVER: 
Failed to parse template [xxx].erb:
      Filepath: /usr/share/ruby/vendor_ruby/puppet/parser/functions/template.rb
      Line: 10
      Detail: undefined method `collect' for "referenced_template.erb":String
     at /etc/puppet/modules/[yyy].pp:164 on node [zzz.example]

It looks like the `template` function is invoking `collect` on its argument 
regardless of whether it's a String or Array, which works in Ruby 1.8 
(`'abc'.collect` behaves like `['abc'].collect`) but not in 1.9. Passing an 
Array works with both versions.

This is on Fedora 17, Ruby 1.9.3p194, with Puppet 2.7.18.


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to