Module: Puppet::Util::ClassGen

Includes:
Puppet::Util, MethodHelper
Included in:
MetaType::Manager, Reports, Type, FileType, Instrumentation, Log
Defined in:
lib/vendor/puppet/util/classgen.rb

Constant Summary

Constants included from Puppet::Util

AbsolutePathPosix, AbsolutePathWindows

Instance Method Summary collapse

Methods included from Puppet::Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from MethodHelper

#requiredopts, #set_options, #symbolize_options

Instance Method Details

#genclass(name, options = {}, &block) ⇒ Object

Create a new subclass. Valid options are:

  • :array: An array of existing classes. If specified, the new class is added to this array.

  • :attributes: A hash of attributes to set before the block is evaluated.

  • :block: The block to evaluate in the context of the class. You can also just pass the block normally, but it will still be evaluated with class_eval.

  • :constant: What to set the constant as. Defaults to the capitalized name.

  • :hash: A hash of existing classes. If specified, the new class is added to this hash, and it is also used for overwrite tests.

  • :overwrite: Whether to overwrite an existing class.

  • :parent: The parent class for the generated class. Defaults to self.

  • :prefix: The constant prefix. Default to nothing; if specified, the capitalized name is appended and the result is set as the constant.



27
28
29
# File 'lib/vendor/puppet/util/classgen.rb', line 27

def genclass(name, options = {}, &block)
  genthing(name, Class, options, block)
end

#genmodule(name, options = {}, &block) ⇒ Object

Create a new module. Valid options are:

  • :array: An array of existing classes. If specified, the new class is added to this array.

  • :attributes: A hash of attributes to set before the block is evaluated.

  • :block: The block to evaluate in the context of the class. You can also just pass the block normally, but it will still be evaluated with class_eval.

  • :constant: What to set the constant as. Defaults to the capitalized name.

  • :hash: A hash of existing classes. If specified, the new class is added to this hash, and it is also used for overwrite tests.

  • :overwrite: Whether to overwrite an existing class.

  • :prefix: The constant prefix. Default to nothing; if specified, the capitalized name is appended and the result is set as the constant.



46
47
48
# File 'lib/vendor/puppet/util/classgen.rb', line 46

def genmodule(name, options = {}, &block)
  genthing(name, Module, options, block)
end

#rmclass(name, options) ⇒ Object

Remove an existing class



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vendor/puppet/util/classgen.rb', line 51

def rmclass(name, options)
  options = symbolize_options(options)
  const = genconst_string(name, options)
  retval = false
  if const_defined?(const)
    remove_const(const)
    retval = true
  end

  if hash = options[:hash] and hash.include? name
    hash.delete(name)
    retval = true
  end

  # Let them know whether we did actually delete a subclass.
  retval
end