Module: Puppet::Util::MethodHelper
- Included in:
- FileServing::Base, Indirector::Indirection, Interface::Action, Parameter, Parser::AST, Parser::Compiler, Parser::Resource, Parser::Resource::Param, Parser::Scope, Transaction::Event, Autoload, ClassGen, FileParsing::FileRecord, Ldap::Connection, ProviderFeatures::ProviderFeature, Reference
- Defined in:
- lib/puppet/util/methodhelper.rb
Overview
Where we store helper methods related to, um, methods.
Instance Method Summary collapse
- #requiredopts(*names) ⇒ Object
-
#set_options(options) ⇒ Object
Iterate over a hash, treating each member as an attribute.
-
#symbolize_options(options) ⇒ Object
Take a hash and convert all of the keys to symbols if possible.
Instance Method Details
#requiredopts(*names) ⇒ Object
3 4 5 6 7 |
# File 'lib/puppet/util/methodhelper.rb', line 3 def requiredopts(*names) names.each do |name| devfail("#{name} is a required option for #{self.class}") if self.send(name).nil? end end |
#set_options(options) ⇒ Object
Iterate over a hash, treating each member as an attribute.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/puppet/util/methodhelper.rb', line 10 def () .each do |param,value| method = param.to_s + "=" if respond_to? method self.send(method, value) else raise ArgumentError, "Invalid parameter #{param} to object class #{self.class}" end end end |
#symbolize_options(options) ⇒ Object
Take a hash and convert all of the keys to symbols if possible.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/puppet/util/methodhelper.rb', line 22 def () .inject({}) do |hash, opts| if opts[0].respond_to? :intern hash[opts[0].intern] = opts[1] else hash[opts[0]] = opts[1] end hash end end |