class Puppet::ModuleTool::ContentsDescription

ContentsDescription

This class populates Metadata's Puppet type information.

Public Class Methods

new(module_path) click to toggle source

Instantiate object for string module_path.

   # File lib/puppet/module_tool/contents_description.rb
11 def initialize(module_path)
12   @module_path = module_path
13 end

Public Instance Methods

annotate(metadata) click to toggle source

Update Metadata's Puppet type information.

   # File lib/puppet/module_tool/contents_description.rb
16 def annotate(metadata)
17   metadata.types.replace data.clone
18 end
attr_doc(type, kind) click to toggle source

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
65 def attr_doc(type, kind)
66   attrs = []
67 
68   type.allattrs.each do |name|
69     if type.attrtype(name) == kind && name != :provider
70       attrs.push(:name => name, :doc => type.attrclass(name).doc)
71     end
72   end
73 
74   attrs
75 end
data() click to toggle source

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 Puppet type.

  • :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
31 def data
32   unless @data
33     @data = []
34     type_names = []
35     for module_filename in Dir[File.join(@module_path, "lib/puppet/type/*.rb")]
36       require module_filename
37       type_name = File.basename(module_filename, ".rb")
38       type_names << type_name
39 
40       for provider_filename in Dir[File.join(@module_path, "lib/puppet/provider/#{type_name}/*.rb")]
41         require provider_filename
42       end
43     end
44 
45     type_names.each do |name|
46       type = Puppet::Type.type(name.to_sym)
47       if type
48         type_hash = {:name => name, :doc => type.doc}
49         type_hash[:properties] = attr_doc(type, :property)
50         type_hash[:parameters] = attr_doc(type, :param)
51         if type.providers.size > 0
52           type_hash[:providers] = provider_doc(type)
53         end
54         @data << type_hash
55       else
56         Puppet.warning _("Could not find/load type: %{name}") % { name: name }
57       end
58     end
59   end
60   @data
61 end
provider_doc(type) click to toggle source

Return an array of hashes representing this type's providers, each containing :name and :doc.

   # File lib/puppet/module_tool/contents_description.rb
79 def provider_doc(type)
80   providers = []
81 
82   type.providers.sort.each do |prov|
83     providers.push(:name => prov, :doc => type.provider(prov).doc)
84   end
85 
86   providers
87 end