Class: Puppet::Module::Tool::ContentsDescription
- Inherits:
- 
      Object
      
        - Object
- Puppet::Module::Tool::ContentsDescription
 
- Defined in:
- lib/puppet/module/tool/contents_description.rb
Overview
ContentsDescription
This class populates Metadata‘s Puppet type information.
Instance Method Summary collapse
- 
  
    
      #annotate(metadata)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Update Metadata‘s Puppet type information.
- 
  
    
      #attr_doc(type, kind)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return an array of hashes representing this type‘s attrs ofkind(e.g. :param or :property), each containing :name and :doc.
- 
  
    
      #data  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return types for this module. 
- 
  
    
      #initialize(module_path)  ⇒ ContentsDescription 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Instantiate object for string module_path.
- 
  
    
      #provider_doc(type)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return an array of hashes representing this type‘s providers, each containing :name and :doc.
Constructor Details
#initialize(module_path) ⇒ ContentsDescription
Instantiate object for string module_path.
| 9 10 11 | # File 'lib/puppet/module/tool/contents_description.rb', line 9 def initialize(module_path) @module_path = module_path end | 
Instance Method Details
#annotate(metadata) ⇒ Object
Update Metadata‘s Puppet type information.
| 14 15 16 | # File 'lib/puppet/module/tool/contents_description.rb', line 14 def annotate() .types.replace data.clone end | 
#attr_doc(type, kind) ⇒ Object
Return an array of hashes representing this type‘s attrs of kind (e.g. :param or :property), each containing :name and :doc.
| 62 63 64 65 66 67 68 69 70 | # File 'lib/puppet/module/tool/contents_description.rb', line 62 def attr_doc(type, kind) returning([]) do |attrs| type.allattrs.each do |name| if type.attrtype(name) == kind && name != :provider attrs.push(:name => name, :doc => type.attrclass(name).doc) end end end end | 
#data ⇒ Object
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?
| 29 30 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 | # File 'lib/puppet/module/tool/contents_description.rb', line 29 def data unless @data @data = [] type_names = [] for module_filename in Dir[File.join(@module_path, "lib/puppet/type/*.rb")] require module_filename type_name = File.basename(module_filename, ".rb") type_names << type_name for provider_filename in Dir[File.join(@module_path, "lib/puppet/provider/#{type_name}/*.rb")] require provider_filename end end type_names.each do |type_name| if type = Puppet::Type.type(type_name.to_sym) type_hash = {:name => type_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 puts "Could not find/load type: #{type_name}" end end end @data end | 
#provider_doc(type) ⇒ Object
Return an array of hashes representing this type‘s providers, each containing :name and :doc.
| 74 75 76 77 78 79 80 | # File 'lib/puppet/module/tool/contents_description.rb', line 74 def provider_doc(type) returning([]) do |providers| type.providers.sort_by{ |o| o.to_s }.each do |prov| providers.push(:name => prov, :doc => type.provider(prov).doc) end end end |