On Apr 9, 2013, at 6:42 AM, Peter Meier <[email protected]> wrote:
> -----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
Hi Peter,
I'm confident there's an easier way; just the way you're using the autoloader
there seems unecessarily complicated. Why are you even using autoloading? Why
don't you just hard-code the invalidator name, and use normal 'require' or
something similar?
--
Luke Kanies | http://about.me/lak | http://puppetlabs.com/ | +1-615-594-8199
Join us at PuppetConf 2013, August 22-23 in San Francisco -
http://bit.ly/pupconf13
--
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.