Markus, Thanks for the extended explanation. This is something that should be stuck up on the Type dev wiki.
I'll try to get around to it, but no promises :-/. Thanks, Trevor On Fri, Mar 4, 2011 at 7:07 PM, Markus Roberts <mar...@puppetlabs.com> wrote: > > >> >> The title_pattern method is used in resource.rb in the parse_title >> method. It will expect that you return an (not really intuitive) array >> of the form >> >> [ [ regex1, ARRAY ], [ regex2, ARRAY ] ] >> >> with ARRAY = [ [:namevar1, proc_that_is_called_with_namevar1], ... >> ,[:namevarN, proc ] ] >> >> In you example your title_pattern method could return >> [ [ /^(.*):(.*)$/, [ [ :target, lambda{|x| x} ], [:username, lambda{|x| >> x}] ] ] ] > > At one point this had been simpler but apparently that got refactored away; > in the older code, if you didn't want the name munged the lambda {|x| x} > (a.k.a. identity) could be omitted. > > The idea here (to render the situation a little more intelligible) is that > you can specify an ordered list of title patterns, and the first one that > matches is used to set the corresponding namevar-components. To accomplish > this, each pattern is associated with an array of property names (as > symbols) and a munging function (the lambda) which can be used to extract / > reformat the data. There should be the same number of these as there are > groups in the regular expression, and they will be passed the matching part > of the title. > > If no pattern matches no properties are set and you have to specify them > yourself. I believe this basically giver you what you want: > >> What I'd like is this: >> >> foo { "meaningless_name": >> target => "/some/path", >> username => "username" >> } >> > > with no extra fuss. Because there is only one pattern, so long as > "meaningless_name" doesn't contain a colon, it won't set any of the > components of the namevar, and you'll get the uniqueness restrictions you > want. > > You don't have to do: > >> >> Then, in foo.rb, I'd like to be able to say: >> >> :namevar = "#{target}:#{username} > > because that's in effect a subset of what the composite namevar system is > doing. > > I'd actually advise tightening the regular expression somewhat (as I'd > originally suggested) to at least make sure the user name was well formed > (and specifically, did not contain a colon), say something like: > > [ [ /^(.+):([a-zA-Z_0-9]+)$/, [ [ :target, lambda{|x| x} ], [:username, > lambda{|x| x}] ] ] ] > > and perhaps even further, to specify valid paths or...?. Since you aren't > planning on using the decomposition mechanism in most cases, it would make > sense to have it as tight as reasonably possible so as to prevent it > "accidentally" doing you any favours, while still leaving it correct* for > the cases where you do decide to use it. > > Conversely, I suppose you could have title_patterns just return: > > [] > > meaning "there are no supported ways to parse the title into namevar > components" which would require that the target and username always be > specified and collectively unique within the type, well as the usual > requirement that the title be unique withing the type. > > -- M > * That is, you'd want to make sure that would still accept all valid user > names. > ----------------------------------------------------------- > When in trouble or in doubt, run in circles, > scream and shout. -- 1920's parody of the > maritime general prudential rule > ------------------------------------------------------------ > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to puppet-dev@googlegroups.com. > To unsubscribe from this group, send email to > puppet-dev+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > -- Trevor Vaughan Vice President, Onyx Point, Inc (410) 541-6699 tvaug...@onyxpoint.com -- This account not approved for unencrypted proprietary information -- -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.