Module Puppet::MetaType::Manager
In: lib/puppet/metatype/manager.rb

Methods

allclear   eachtype   loadall   newtype   rmtype   type   typeloader  

Included Modules

Puppet::Util::ClassGen

Public Instance methods

remove all type instances; this is mostly only useful for testing

[Source]

    # File lib/puppet/metatype/manager.rb, line 11
11:     def allclear
12:         @types.each { |name, type|
13:             type.clear
14:         }
15:     end

iterate across all of the subclasses of Type

[Source]

    # File lib/puppet/metatype/manager.rb, line 18
18:     def eachtype
19:         @types.each do |name, type|
20:             # Only consider types that have names
21:             #if ! type.parameters.empty? or ! type.validproperties.empty?
22:                 yield type 
23:             #end
24:         end
25:     end

Load all types. Only currently used for documentation.

[Source]

    # File lib/puppet/metatype/manager.rb, line 28
28:     def loadall
29:         typeloader.loadall
30:     end

Define a new type.

[Source]

    # File lib/puppet/metatype/manager.rb, line 33
33:     def newtype(name, options = {}, &block)
34:         # Handle backward compatibility
35:         unless options.is_a?(Hash)
36:             Puppet.warning "Puppet::Type.newtype(%s) now expects a hash as the second argument, not %s" % [name, options.inspect]
37:             options = {:parent => options}
38:         end
39: 
40:         # First make sure we don't have a method sitting around
41:         name = symbolize(name)
42:         newmethod = "new#{name.to_s}"
43: 
44:         # Used for method manipulation.
45:         selfobj = metaclass()
46: 
47:         @types ||= {}
48: 
49:         if @types.include?(name)
50:             if self.respond_to?(newmethod)
51:                 # Remove the old newmethod
52:                 selfobj.send(:remove_method,newmethod)
53:             end
54:         end
55: 
56:         options = symbolize_options(options)
57: 
58:         if parent = options[:parent]
59:             options.delete(:parent)
60:         end
61: 
62:         # Then create the class.
63:         klass = genclass(name,
64:             :parent => (parent || Puppet::Type),
65:             :overwrite => true,
66:             :hash => @types,
67:             :attributes => options,
68:             &block
69:         )
70: 
71:         # Now define a "new<type>" method for convenience.
72:         if self.respond_to? newmethod
73:             # Refuse to overwrite existing methods like 'newparam' or 'newtype'.
74:             Puppet.warning "'new#{name.to_s}' method already exists; skipping"
75:         else
76:             selfobj.send(:define_method, newmethod) do |*args|
77:                 klass.create(*args)
78:             end
79:         end
80: 
81:         # If they've got all the necessary methods defined and they haven't
82:         # already added the property, then do so now.
83:         if klass.ensurable? and ! klass.validproperty?(:ensure)
84:             klass.ensurable
85:         end
86: 
87:         # Now set up autoload any providers that might exist for this type.
88:         klass.providerloader = Puppet::Util::Autoload.new(klass,
89:             "puppet/provider/#{klass.name.to_s}"
90:         )
91: 
92:         # We have to load everything so that we can figure out the default type.
93:         klass.providerloader.loadall()
94: 
95:         klass
96:     end

Remove an existing defined type. Largely used for testing.

[Source]

     # File lib/puppet/metatype/manager.rb, line 99
 99:     def rmtype(name)
100:         # Then create the class.
101:         klass = rmclass(name,
102:             :hash => @types
103:         )
104:         
105:         if respond_to?("new" + name.to_s)
106:             metaclass.send(:remove_method, "new" + name.to_s)
107:         end
108:     end

Return a Type instance by name.

[Source]

     # File lib/puppet/metatype/manager.rb, line 111
111:     def type(name)
112:         @types ||= {}
113: 
114:         name = name.to_s.downcase.to_sym
115: 
116:         if t = @types[name]
117:             return t
118:         else
119:             if typeloader.load(name)
120:                 unless @types.include? name
121:                     Puppet.warning "Loaded puppet/type/#{name} but no class was created"
122:                 end
123:             end
124: 
125:             return @types[name]
126:         end
127:     end

Create a loader for Puppet types.

[Source]

     # File lib/puppet/metatype/manager.rb, line 130
130:     def typeloader
131:         unless defined? @typeloader
132:             @typeloader = Puppet::Util::Autoload.new(self,
133:                 "puppet/type", :wrap => false
134:             )
135:         end
136: 
137:         @typeloader
138:     end

[Validate]