Greetings, puppeteers. As per yesterday''s discussion on if a file exists on the pupper master, I decided to write a custom function. I''m prolific in a lot of languages unfortunately, ruby isn''t one of them. Here''s my function: module Puppet::Parser::Functions newfunction(:file_exists) do |args| filename = args[0] return File.exists?(filename) end end That seems straightforward but it barfs with the following error: err: Could not retrieve configuration: Function ''file_exists'' does not return a value Seriously? The exists instance method is a boolean. What do you mean it doesn''t return a value? I humored it with this version: module Puppet::Parser::Functions newfunction(:file_exists) do |args| filename = args[0] if File.exists?(filename) return true else return false end end end But the results were identical. Any thoughts for a ruby noob. Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
you are missing the type in the function.. For example: newfunction(:func, :type =>rvalue) do... Cheers, Ohad On 12/9/08, Jeff <joesiege@gmail.com> wrote:> > Greetings, puppeteers. As per yesterday''s discussion on if a file > exists on the pupper master, I decided to write a custom function. I''m > prolific in a lot of languages unfortunately, ruby isn''t one of them. > Here''s my function: > > module Puppet::Parser::Functions > > newfunction(:file_exists) do |args| > filename = args[0] > return File.exists?(filename) > end > > end > > > That seems straightforward but it barfs with the following error: > > err: Could not retrieve configuration: Function ''file_exists'' does not > return a value > > Seriously? The exists instance method is a boolean. What do you mean > it doesn''t return a value? > > I humored it with this version: > > module Puppet::Parser::Functions > > newfunction(:file_exists) do |args| > filename = args[0] > if File.exists?(filename) > return true > else > return false > end > end > > end > > But the results were identical. Any thoughts for a ruby noob. > > Jeff > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 9, 9:36 am, "Ohad Levy" <ohadl...@gmail.com> wrote:> you are missing the type in the function.. For example: > > newfunction(:func, :type =>rvalue) do... > > Cheers, > Ohad >Thanks. I had to preface rvalue with a : as in newfunction (:func, :type => :rvalue) Can anybody recommend a good english language introductory Ruby book for programmers? I know C, java, perl and php like the back of my hand but ruby seems alien. Cheers, Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Hope this will help: http://www.rubycentral.com/book/ Rodney On Dec 9, 11:14 pm, Jeff <joesi...@gmail.com> wrote:> On Dec 9, 9:36 am, "Ohad Levy" <ohadl...@gmail.com> wrote: > > > you are missing the type in the function.. For example: > > > newfunction(:func, :type =>rvalue) do... > > > Cheers, > > Ohad > > Thanks. I had to preface rvalue with a : as in newfunction > (:func, :type => :rvalue) > > Can anybody recommend a good english language introductory Ruby book > for programmers? I know C, java, perl and php like the back of my hand > but ruby seems alien. > > Cheers, > Jeff--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---