puppet_settings.rb 604 B

12345678910111213141516
  1. # A method to evaluate a Facter code block if puppet is loaded.
  2. module Facter::Util::PuppetSettings
  3. # This method is intended to provide a convenient way to evaluate a
  4. # Facter code block only if Puppet is loaded. This is to account for the
  5. # situation where the fact happens to be in the load path, but Puppet is
  6. # not loaded for whatever reason. Perhaps the user is simply running
  7. # facter without the --puppet flag and they happen to be working in a lib
  8. # directory of a module.
  9. def self.with_puppet
  10. Module.const_get('Puppet')
  11. rescue NameError
  12. nil
  13. else
  14. yield
  15. end
  16. end