Issue #6758 has been updated by Pieter van de Bruggen.

We should provide the interface demonstrated on the last line of the ticket's 
body, but providing the options hash should be optional.

Also, since the block provided for the action is unlikely to (read: not going 
to) contain a slot for the options hash, we should make the hash available as a 
call to the method `options`.

    Puppet::Interface.new :action do
      options[:foo]
    end

This solution should be as tightly localized to the invocation of the action as 
possible -- global variables / properties are not acceptable (or safe).
----------------------------------------
Bug #6758: When calling interfaces through Ruby, options should be passed as an 
argument
https://projects.puppetlabs.com/issues/6758

Author: Paul Berry
Status: Accepted
Priority: Normal
Assignee: 
Category: interfaces
Target version: 2.6.x
Affected Puppet version: 
Keywords: 
Branch: 


In the current implementation of interfaces, in order to pass an option to an 
interface action, one must set the option on the interface object itself, 
either like this:

    interface = Puppet::Interface.interface(:<interface_name>)
    interface.options = <options_hash>
    interface.<action>(<args>)

Or like this:

    Puppet::Interface::<Interface_name>.options = <options_hash>
    Puppet::Interface::<Interface_name>.<action>(<args>)

In addition to being clumsy, this places the options in a location that is 
effectively global, so it carries all the disadvantages of global variables.  
For example, if the implementation of action 1 calls action 2, and the 
implementation of action 2 changes the options and calls action 3, then there 
is a danger that the implementor of action 2 will forget to restore the options 
back to the initial state before returning to action 1.

Also, all kinds of havoc is likely to ensue if this mechanism is ever used in a 
multithreaded context.

It would be far better if we passed the options to the action using the 
conventional Ruby options hash mechanism:

    Puppet::Interface::<Interface_name>.<action>(<args>, <options_hash>)


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