On Mon, Sep 10, 2012 at 10:07:14AM -0400, Trevor Vaughan wrote:
> All,
> 
> Is it possible to use default values in a composite namevar?
> 
> I'm having a heck of a time making it work properly.
> 
> I tried:
> 
> def self.title_patterns
>     [
>       [
>         /^(.*)$/,
>        [
>           [:path, lambda{|x| x }],
>           [:function, lambda{|x| x }]
>         ]
>       ]
>     ]
>     end
> 

You have to define two title_patterns. If you have one title pattern
(that may set :path to nil and :function to "foo") it won't work.

I once tried to write a /etc/service provider (#5660) and wanted to have
the name (e.g. "domain") and protocol (e.g. "udp") to be namevars and to
have tcp as the default protocol. I looked at my title pattern and
noticed this comment:

    def self.title_patterns
      [
        # we have two title_patterns "name" and "name:protocol". We won't use
        # one pattern (that will eventually set :protocol to nil) because we
        # want to use a default value for :protocol. And that does only work
        # if :protocol is not put in the parameter hash while initialising
        [
          /^(.*?)\/(tcp|udp)$/, # Set name and protocol
          [
            # We don't need a lot of post-parsing
            [ :name, lambda{|x| x} ],
            [ :protocol, lambda{ |x| x.intern unless x.nil? } ]
          ]
        ],
        [
          /^(.*)$/,
          [
            [ :name, lambda{|x| x} ]
          ]
        ]
      ]
    end

I hope this helps.

-Stefan


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" 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-dev?hl=en.

Reply via email to