diff options
Diffstat (limited to 'lib/puppet/util/methodhelper.rb')
-rw-r--r-- | lib/puppet/util/methodhelper.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/util/methodhelper.rb b/lib/puppet/util/methodhelper.rb index 5643ac245..c229e8efb 100644 --- a/lib/puppet/util/methodhelper.rb +++ b/lib/puppet/util/methodhelper.rb @@ -1,5 +1,26 @@ # Where we store helper methods related to, um, methods. module Puppet::Util::MethodHelper + def requiredopts(*names) + names.each do |name| + if self.send(name).nil? + devfail("%s is a required option for %s" % [name, self.class]) + end + end + end + + # Iterate over a hash, treating each member as an attribute. + def set_options(options) + options.dup.each do |param,value| + method = param.to_s + "=" + unless self.respond_to?(method) + self.fail "Invalid parameter %s to object class %s" % + [param,self.class.to_s] + end + + self.send(method,value) + end + end + # Take a hash and convert all of the keys to symbols if possible. def symbolize_options(options) options.inject({}) do |hash, opts| |