Skip to content

Commit 79889af

Browse files
committed
(#18023) Document user facing classes using yardoc and show api.
This adds yardoc to user facing classes Type, Parameter, Property, Provider, Report, as well as classes used by these via inclusion or delegation and where documetation was most relevant to add at the source. This also includes puppet specific tags (@comment, and @dsl), puppet specific templates (shows DSL for elements marked with @dsl), as well as some general improvements to the default yard templates. As this is the first stab at providing more comprehensive code documentation, there are many unanswered questions in the documentation that are marked with @todo, or ??? to indicate uncertainty. More investigation is required to update these. Many methods are marked as being non api. As this documentation is not final, and only covers a portion of the puppet code base, the lack of a "private" tag being displayed should not yet be taken as authoritiative indication that it is api.
1 parent a576f25 commit 79889af

23 files changed

+2331
-458
lines changed

.yardopts

+2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
--transitive-tag status
88
--tag comment
99
--hide-tag comment
10+
--tag dsl:"DSL"
1011
--no-transitive-tag api
12+
--template-path yardoc/templates
1113
lib/**/*.rb

lib/puppet/metatype/manager.rb

+46-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22
require 'puppet/util/classgen'
33
require 'puppet/node/environment'
44

5-
# Methods dealing with Type management. This module gets included into the
6-
# Puppet::Type class, it's just split out here for clarity.
5+
# This module defines methods dealing with Type management.
6+
# This module gets included into the Puppet::Type class, it's just split out here for clarity.
7+
# @api public
8+
#
79
module Puppet::MetaType
810
module Manager
911
include Puppet::Util::ClassGen
1012

11-
# remove all type instances; this is mostly only useful for testing
13+
# An implementation specific method that removes all type instances during testing.
14+
# @note Only use this method for testing purposes.
15+
# @api private
16+
#
1217
def allclear
1318
@types.each { |name, type|
1419
type.clear
1520
}
1621
end
1722

18-
# iterate across all of the subclasses of Type
23+
# Iterates over all already loaded Type subclasses.
24+
# @yield [t] a block receiving each type
25+
# @yieldparam t [Puppet::Type] each defined type
26+
# @yieldreturn [Object] the last returned object is also returned from this method
27+
# @return [Object] the last returned value from the block.
1928
def eachtype
2029
@types.each do |name, type|
2130
# Only consider types that have names
@@ -25,12 +34,31 @@ def eachtype
2534
end
2635
end
2736

28-
# Load all types. Only currently used for documentation.
37+
# Loads all types.
38+
# @note Should only be used for purposes such as generating documentation as this is potentially a very
39+
# expensive operation.
40+
# @return [void]
41+
#
2942
def loadall
3043
typeloader.loadall
3144
end
3245

33-
# Define a new type.
46+
# Defines a new type or redefines an existing type with the given name.
47+
# A convenience method on the form `new<name>` where name is the name of the type is also created.
48+
# (If this generated method happens to clash with an existing method, a warning is issued and the original
49+
# method is kept).
50+
#
51+
# @param name [String] the name of the type to create or redefine.
52+
# @param options [Hash] options passed on to {Puppet::Util::ClassGen#genclass} as the option `:attributes` after
53+
# first having removed any present `:parent` option.
54+
# @option options [Puppet::Type] :parent the parent (super type) of this type. If nil, the default is
55+
# Puppet::Type. This option is not passed on as an attribute to genclass.
56+
# @yield [ ] a block evaluated in the context of the created class, thus allowing further detailing of
57+
# that class.
58+
# @return [Class<inherits Puppet::Type>] the created subclass
59+
# @see Puppet::Util::ClassGen.genclass
60+
#
61+
# @dsl type
3462
# @api public
3563
def newtype(name, options = {}, &block)
3664
# Handle backward compatibility
@@ -97,7 +125,9 @@ def newtype(name, options = {}, &block)
97125
klass
98126
end
99127

100-
# Remove an existing defined type. Largely used for testing.
128+
# Removes an existing type.
129+
# @note Only use this for testing.
130+
# @api private
101131
def rmtype(name)
102132
# Then create the class.
103133

@@ -106,7 +136,11 @@ def rmtype(name)
106136
singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}")
107137
end
108138

109-
# Return a Type instance by name.
139+
# Returns a Type instance by name.
140+
# This will load the type if not already defined.
141+
# @param [String, Symbol] name of the wanted Type
142+
# @return [Puppet::Type, nil] the type or nil if the type was not defined and could not be loaded
143+
#
110144
def type(name)
111145
@types ||= {}
112146

@@ -130,7 +164,10 @@ def type(name)
130164
return @types[name]
131165
end
132166

133-
# Create a loader for Puppet types.
167+
# Creates a loader for Puppet types.
168+
# Defaults to an instance of {Puppet::Util::Autoload} if no other auto loader has been set.
169+
# @return [Puppet::Util::Autoload] the loader to use.
170+
# @api private
134171
def typeloader
135172
unless defined?(@typeloader)
136173
@typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => false)

0 commit comments

Comments
 (0)