Module: Puppet::MetaType::Manager
Constant Summary
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows
Instance Method Summary collapse
-
#allclear ⇒ Object
remove all type instances; this is mostly only useful for testing.
-
#eachtype ⇒ Object
iterate across all of the subclasses of Type.
-
#loadall ⇒ Object
Load all types.
-
#newtype(name, options = {}, &block) ⇒ Object
Define a new type.
-
#rmtype(name) ⇒ Object
Remove an existing defined type.
-
#type(name) ⇒ Object
Return a Type instance by name.
-
#typeloader ⇒ Object
Create a loader for Puppet types.
Methods included from Util::ClassGen
#genclass, #genmodule, #rmclass
Methods included from 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 Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Instance Method Details
#allclear ⇒ Object
remove all type instances; this is mostly only useful for testing
11 12 13 14 15 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 11 def allclear @types.each { |name, type| type.clear } end |
#eachtype ⇒ Object
iterate across all of the subclasses of Type
18 19 20 21 22 23 24 25 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 18 def eachtype @types.each do |name, type| # Only consider types that have names #if ! type.parameters.empty? or ! type.validproperties.empty? yield type #end end end |
#loadall ⇒ Object
Load all types. Only currently used for documentation.
28 29 30 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 28 def loadall typeloader.loadall end |
#newtype(name, options = {}, &block) ⇒ Object
Define a new type.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 33 def newtype(name, = {}, &block) # Handle backward compatibility unless .is_a?(Hash) Puppet.warning "Puppet::Type.newtype(#{name}) now expects a hash as the second argument, not #{.inspect}" = {:parent => } end # First make sure we don't have a method sitting around name = name.intern newmethod = "new#{name}" # Used for method manipulation. selfobj = singleton_class @types ||= {} if @types.include?(name) if self.respond_to?(newmethod) # Remove the old newmethod selfobj.send(:remove_method,newmethod) end end = () if parent = [:parent] .delete(:parent) end # Then create the class. klass = genclass( name, :parent => (parent || Puppet::Type), :overwrite => true, :hash => @types, :attributes => , &block ) # Now define a "new<type>" method for convenience. if self.respond_to? newmethod # Refuse to overwrite existing methods like 'newparam' or 'newtype'. Puppet.warning "'new#{name.to_s}' method already exists; skipping" else selfobj.send(:define_method, newmethod) do |*args| klass.new(*args) end end # If they've got all the necessary methods defined and they haven't # already added the property, then do so now. klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure) # Now set up autoload any providers that might exist for this type. klass.providerloader = Puppet::Util::Autoload.new(klass, "puppet/provider/#{klass.name.to_s}") # We have to load everything so that we can figure out the default provider. klass.providerloader.loadall klass.providify unless klass.providers.empty? klass end |
#rmtype(name) ⇒ Object
Remove an existing defined type. Largely used for testing.
99 100 101 102 103 104 105 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 99 def rmtype(name) # Then create the class. klass = rmclass(name, :hash => @types) singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}") end |
#type(name) ⇒ Object
Return a Type instance by name.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/vendor/puppet/metatype/manager.rb', line 108 def type(name) @types ||= {} # We are overwhelmingly symbols here, which usually match, so it is worth # having this special-case to return quickly. Like, 25K to 300 symbols to # strings in this method. --daniel 2012-07-17 return @types[name] if @types[name] # Try mangling the name, if it is a string. if name.is_a? String name = name.downcase.intern return @types[name] if @types[name] end # Try loading the type. if typeloader.load(name, Puppet::Node::Environment.current) Puppet.warning "Loaded puppet/type/#{name} but no class was created" unless @types.include? name end # ...and I guess that is that, eh. return @types[name] end |