-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

I'm currently working on an own terminus for the catalog. One of the
ideas of this terminus is, that it can ask a configurable invalidator,
whether a certain catalog is still valid or not.
This invalidator should also be configurable in an own
terminus-dedicated config file and also deliverable by puppet modules.

So to load that invalidator I'm currently doing:

- ---
  def invalidator
    @invalidator ||= begin
      name = config['invalidator']
      Puppet::Util::Autoload.new(self, \
        'puppet/cm_guard').load(name)
      const_name = Puppet::Indirector::Terminus.name2const(name)
      klass = "Puppet::CmGuard::#{const_name}"
      constantize(klass).new
    end
  end

  # TODO: there is for sure some internal puppet code that does that
  # for me
  def constantize(camel_cased_word)
    names = camel_cased_word.split('::')
    names.shift if names.empty? || names.first.empty?

    constant = Object
    names.each do |name|
      constant = constant.const_defined?(name) ? \
        constant.const_get(name) : constant.const_missing(name)
    end
    constant
  end
- ---

I think I did the right thing by using Puppet::Util::Autoload to load
the file and make it possible that it is also distributable via module
lib dirs.
However as you see on my TODO: I'm not really happy how I get the
class instance from my config string. constantize is just copied over
from activesupport.

Is there an easier way to do that in puppet, similar to how I can do
it in rails? Aka. some_string.constantize

Thanks

~pete
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlFkGrgACgkQbwltcAfKi39PqQCgp2opZ9xZynvbnYwmfUrIdW5g
PsUAoJ1JTu925CL3l8P1EieFS92vlpkD
=aJTZ
-----END PGP SIGNATURE-----

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to