Sha256: 6837942346367b0ccbe3ca6ff71d22d65b4c56ae3bd5091a0cb48010efa23654

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

# 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.each do |param,value|
            method = param.to_s + "="
            begin
                self.send(method, value)
            rescue NoMethodError
                raise ArgumentError, "Invalid parameter %s to object class %s" %
                        [param,self.class.to_s]
            end
        end
    end

    # Take a hash and convert all of the keys to symbols if possible.
    def symbolize_options(options)
        options.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
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-0.24.9 lib/puppet/util/methodhelper.rb
puppet-0.25.1 lib/puppet/util/methodhelper.rb
puppet-0.25.0 lib/puppet/util/methodhelper.rb
puppet-0.24.0 lib/puppet/util/methodhelper.rb
puppet-0.24.2 lib/puppet/util/methodhelper.rb
puppet-0.24.3 lib/puppet/util/methodhelper.rb
puppet-0.24.4 lib/puppet/util/methodhelper.rb
puppet-0.24.1 lib/puppet/util/methodhelper.rb
puppet-0.24.6 lib/puppet/util/methodhelper.rb
puppet-0.24.5 lib/puppet/util/methodhelper.rb
puppet-0.24.7 lib/puppet/util/methodhelper.rb
puppet-0.24.8 lib/puppet/util/methodhelper.rb