Issue #14894 has been updated by Michael Keller.

could be written as should be:

<pre><code class="ruby">
Puppet::Parser::Functions::newfunction(:setup_virtualclass, :doc => ‘write 
stuff here’) do |args|

   args.flatten.each do |classname|
      Puppet::Parser::evaluate(“if !defined(Setup::Virtualclass[#{classname}]) 
{ @setup::virtualclass { #{classname}: } }”)
  end

end 
</code></pre>
----------------------------------------
Feature #14894: eval function for puppet DSL as ruby function
https://projects.puppetlabs.com/issues/14894#change-64612

Author: Michael Keller
Status: Unreviewed
Priority: Normal
Assignee: 
Category: API
Target version: 
Affected Puppet version: 
Keywords: eval
Branch: 


it would be super to have a ruby function which "evaluates" puppet DSL code. 
that way the knowledge of the inner workings of puppet isn't required to write 
some "macros".

Example (untested code - might be working or not):

`
Puppet::Parser::Functions::newfunction(:setup_virtualclass, :doc => 'write 
stuff here') do |args|
    Puppet::Parser::Functions.autoloader.loadall
    args.flatten.each do |classname|
       next if function_defined("Setup::Virtualclass[#{classname}]")
       function_realize("Setup::Virtualclass[#{classname}]")
    end
end
`
    

could be written as:

`
Puppet::Parser::Functions::newfunction(:setup_virtualclass, :doc => 'write 
stuff here') do |args|

  classname = args[0]

  Puppet::Parser::evaluate("if !defined(Setup::Virtualclass[#{classname}]) { 
@setup::virtualclass { #{classname}: } }")

end
`






-- 
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