I just finished something very similar:

  def self.title_join(hash)
    "#{hash[:domain]}/#{hash[:type]}/#{hash[:item]}"
  end

where the default case was:

+  def self.title_join(hash)
+    case key_attributes.length
+    when 0,1; hash[:name]
+    else
+      Puppet.warning('you should specify a joiner when there are two of
more key a
+    end
+  end

It will be a little while before I can get this code cleaned up into a
patch, it does not quite work yet...


On Sun, May 22, 2011 at 5:48 PM, markus <mar...@reality.com> wrote:

> So what if we replaced this:
>
> 910  title = hash.delete(:title)
> 911  title ||= hash[:name]
> 912  title ||= hash[key_attributes.first] if key_attributes.length == 1
>
> With something that took an array of arrays of strings and symbols and
> "reconstitutes" the title from the first one that matches:
>
>  title = hash.delete(:title)
>  title ||= patterns.
>    collect { |p| p.collect {|x| (x.is_a? Symbol) ? hash[x] : x}}.
>    find { |pattern| pattern.all? { |x| x } }.
>    join('')
>
> And then the default (to get the same behaviour as before) would be:
>
>    [
>     [:name],
>      [key_attributes.first] if key_attributes.length == 1
>     ].compact
>
> ...but could (on a type-by-type basis) include things like:
>
>      [:username,"@",:host,".",:domain]
>
> ....or
>
>      [:protocol,":",:port]
>
> ...or whatever to build parsible titles as needed.
>
> -- Markus
>
>
> --
> 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.
>
>

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

Reply via email to