On Tuesday, December 2, 2014 4:53:42 PM UTC-6, Geoffrey Gardella wrote:
>
> Hey Josh, thanks for the reply.
>
> I'm still struggling with this. I have a hash of the values passed in from 
> the manifest with the keys including '_' which need to be re-written.
>
>   properties => {'john_wayne' => '1', 'liberty_valance' => '0', ...}
>
> this needs to become:
>
>   properties => {'john-wayne' => '1', 'liberty-valance' => '0', ...}
>
> I believe this is where they are defined in my type:
>
> newproperty(:properties) do
>    desc "A hash table of propname=propvalue entries to apply to the link"
> end
>
> So, I should write a method in the type to re-write the keys? Something 
> like (forgive my ruby too):
>
>        def modify_keys(h)
>           h.keys.each do |k|
>               if(k.include? '_') then
>                 h[k.gsub(/_/, '-')] = h[k]
>                 h.delete(k)
>               end
>           end 
>        end
>
> Can I add a method like this to my property? How is such a method then 
> called in the provider?
>
>

It looks like you want to use the munge hook.  Though the docs 
<https://docs.puppetlabs.com/guides/custom_types.html> are a bit unclear, I 
think it works for property definitions (not just for parameter 
definitions).  You would put something like this inside your property 
definition:

      munge do |value|
        value.inject({}) do |xlated, kv|
          k, v = kv
          xlated[k.gsub(/_/, '-')] = v
        end
      end


Note that that assumes the value is a hash; you may want to use the 
validation hook as well to ensure that (or else munge more flexibly).


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/8596ef40-2d31-40ee-b97b-d87b06116399%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to