On May 14, 2010, at 2:50 PM, Paul Lathrop wrote:

> I'm working on a custom type/provider to handle the config file for a
> piece of internal software. The config file is .ini-like and looks
> something like this:
> 
> [common]
> key1 = value1
> key2 = value2
> 
> [section1]
> key3 = value3
> key4 = value4
> 
> ...
> 
> [sectionN]
> key3 = valueN
> key4 = valueN
> 
> In other words, there is a [common] section which defines options that
> affect global operation, then a series of sections (similar to
> environments in puppet.conf) which all have a couple of options they
> set. I think I know how to handle the sections, but not the [common]
> part.
> 
> One thought was to just treat the [common] section like any of the
> other sections, but I'm not sure how to enforce key1 and key2 *only*
> being specified in [common].

You could have an extra option on each param that declared which section it 
worked with.  You'd do this by having a new base class for the params, 
descended from Puppet::Property, and have all of the params be an instance of 
that:

  class Puppet::MyProperty < Puppet::Property
    attr_accessor :global
    def global; global; end
    def should=(value)
        raise ArgumentError if resource[:name] == "common" and ! global?
        raise ArgumentError if resource[:name] != "common" and global?
    end
  end

  newproperty(:foo, :global => true, :parent => Puppet::MyProperty) { ... }

That won't quite do it, but it should come pretty close.

Otherwise, you could have separate resource types, one for the common and one 
for the others.

-- 
Nonreciprocal Laws of Expectations:
   Negative expectations yield negative results. Positive expectations
   yield negative results.
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

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