Issue #6759 has been updated by Daniel Pittman.

Assignee deleted (Daniel Pittman)

----------------------------------------
Refactor #6759: Improve internal option handling pattern
https://projects.puppetlabs.com/issues/6759#change-92314

* Author: Markus Roberts
* Status: Closed
* Priority: Normal
* Assignee: 
* Category: plumbing
* Target version: 3.0.0
* Affected Puppet version: 
* Keywords: 
* Branch: 
----------------------------------------
The code base contains many occurrences of the pattern:

<pre>
      def initialize(..., options = {:op1 => 'default1'})
         options.each { |opt, val| send(opt.to_s + "=", val) } 
         :
</pre>

This is problematic for several reasons; it should be replaced with something 
like:

<pre>
      def initialize(..., options = {})
         options = {
            :opt1 => 'default',
            :opt2 => 'default2',
            :
          }.update options
         @opt1 = options.delete(:opt1)
         @opt2 = options.delete(:opt2)
         :
         raise "Unknown options: #{options.inspect}" unless options.empty?
         :
</pre>

If inheritance is an issue this can be augmented to:
 
(in the base)
<pre>
      def initialize(..., options = {})
         parse_options({
            :opt1 => 'default',
            :opt2 => 'default2',
            :
          }.update options)
         :

      def parse_options(options)
         @opt1 = options.delete(:opt1)
         @opt2 = options.delete(:opt2)
         :
         raise "Unknown options: #{options.inspect}" unless options.empty?
         :
</pre>

(in children)
<pre>
      def initialize(..., options = {})
         super(...,{
            :opt3 => 'default3',
            :opt4 => 'default4',
            :
          }.update options)
         :

      def parse_options(options)
        @opt3 = options.delete(:opt3)
        @opt4 = options.delete(:opt4)
        :
        super(options)
      end
</pre>
      






-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to