class Puppet::ModuleTool::ContentsDescription
ContentsDescription¶ ↑
This class populates Metadata's Puppet type information.
Public Class Methods
Instantiate object for string module_path.
# File lib/puppet/module_tool/contents_description.rb 12 def initialize(module_path) 13 @module_path = module_path 14 end
Public Instance Methods
Update Metadata's Puppet type information.
# File lib/puppet/module_tool/contents_description.rb 17 def annotate(metadata) 18 metadata.types.replace data.clone 19 end
Return an array of hashes representing this type's attrs of kind (e.g. :param or :property), each containing :name and :doc.
# File lib/puppet/module_tool/contents_description.rb 66 def attr_doc(type, kind) 67 attrs = [] 68 69 type.allattrs.each do |name| 70 if type.attrtype(name) == kind && name != :provider 71 attrs.push(:name => name, :doc => type.attrclass(name).doc) 72 end 73 end 74 75 attrs 76 end
Return types for this module. Result is an array of hashes, each of which describes a Puppet type. The type description hash structure is:
-
:name => Name of this
Puppettype. -
:doc => Documentation for this type.
-
:properties => Array of hashes representing the type's properties, each containing :name and :doc.
-
:parameters => Array of hashes representing the type's parameters, each containing :name and :doc.
-
:providers => Array of hashes representing the types providers, each containing :name and :doc.
TODO Write a TypeDescription to encapsulate these structures and logic?
# File lib/puppet/module_tool/contents_description.rb 32 def data 33 unless @data 34 @data = [] 35 type_names = [] 36 for module_filename in Dir[File.join(@module_path, "lib/puppet/type/*.rb")] 37 require module_filename 38 type_name = File.basename(module_filename, ".rb") 39 type_names << type_name 40 41 for provider_filename in Dir[File.join(@module_path, "lib/puppet/provider/#{type_name}/*.rb")] 42 require provider_filename 43 end 44 end 45 46 type_names.each do |name| 47 type = Puppet::Type.type(name.to_sym) 48 if type 49 type_hash = {:name => name, :doc => type.doc} 50 type_hash[:properties] = attr_doc(type, :property) 51 type_hash[:parameters] = attr_doc(type, :param) 52 if type.providers.size > 0 53 type_hash[:providers] = provider_doc(type) 54 end 55 @data << type_hash 56 else 57 Puppet.warning _("Could not find/load type: %{name}") % { name: name } 58 end 59 end 60 end 61 @data 62 end
Return an array of hashes representing this type's providers, each containing :name and :doc.
# File lib/puppet/module_tool/contents_description.rb 80 def provider_doc(type) 81 providers = [] 82 83 type.providers.sort.each do |prov| 84 providers.push(:name => prov, :doc => type.provider(prov).doc) 85 end 86 87 providers 88 end