Class: Puppet::ModuleTool::ContentsDescription Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/module_tool/contents_description.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

ContentsDescription

This class populates Metadata‘s Puppet type information.

Instance Method Summary collapse

Constructor Details

#initialize(module_path) ⇒ ContentsDescription

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Instantiate object for string module_path.



11
12
13
# File 'lib/puppet/module_tool/contents_description.rb', line 11

def initialize(module_path)
  @module_path = module_path
end

Instance Method Details

#annotate(metadata) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update Metadata‘s Puppet type information.



16
17
18
# File 'lib/puppet/module_tool/contents_description.rb', line 16

def annotate()
  .types.replace data.clone
end

#attr_doc(type, kind) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return an array of hashes representing this type‘s attrs of kind (e.g. :param or :property), each containing :name and :doc.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/module_tool/contents_description.rb', line 65

def attr_doc(type, kind)
  attrs = []

  type.allattrs.each do |name|
    if type.attrtype(name) == kind && name != :provider
      attrs.push(:name => name, :doc => type.attrclass(name).doc)
    end
  end

  attrs
end

#dataObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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?



31
32
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
# File 'lib/puppet/module_tool/contents_description.rb', line 31

def data
  unless @data
    @data = []
    type_names = []
    (Dir[File.join(@module_path, "lib/puppet/type/*.rb")]).each do |module_filename|
      require module_filename
      type_name = File.basename(module_filename, ".rb")
      type_names << type_name

      (Dir[File.join(@module_path, "lib/puppet/provider/#{type_name}/*.rb")]).each do |provider_filename|
        require provider_filename
      end
    end

    type_names.each do |name|
      type = Puppet::Type.type(name.to_sym)
      if type
        type_hash = { :name => name, :doc => type.doc }
        type_hash[:properties] = attr_doc(type, :property)
        type_hash[:parameters] = attr_doc(type, :param)
        if type.providers.size > 0
          type_hash[:providers] = provider_doc(type)
        end
        @data << type_hash
      else
        Puppet.warning _("Could not find/load type: %{name}") % { name: name }
      end
    end
  end
  @data
end

#provider_doc(type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



79
80
81
82
83
84
85
86
87
# File 'lib/puppet/module_tool/contents_description.rb', line 79

def provider_doc(type)
  providers = []

  type.providers.sort.each do |prov|
    providers.push(:name => prov, :doc => type.provider(prov).doc)
  end

  providers
end