Class: Oldskool::Puppetdoc

Inherits:
Object
  • Object
show all
Defined in:
lib/oldskool/puppetdoc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Puppetdoc

Returns a new instance of Puppetdoc.



7
8
9
10
11
# File 'lib/oldskool/puppetdoc.rb', line 7

def initialize(type)
  loadall

  settype(type)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/oldskool/puppetdoc.rb', line 5

def type
  @type
end

Instance Method Details

#docObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/oldskool/puppetdoc.rb', line 43

def doc
  param_docs = {:name => type.name,
                :description => type.doc,
                :version => Puppet.version,
                :params => {}, :metaparams => {}}

  type.parameters.each {|param| param_docs[:params][param] = paramdoc(param)}
  type.validproperties.each {|param| param_docs[:params][param] = paramdoc(param)}
  type.metaparams.each {|param| param_docs[:metaparams][param] = paramdoc(param)}

  param_docs
end

#loadallObject



13
14
15
# File 'lib/oldskool/puppetdoc.rb', line 13

def loadall
  Puppet::Type.loadall unless Puppet::Type.constants.include?("File")
end

#paramdoc(param) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/oldskool/puppetdoc.rb', line 22

def paramdoc(param)
  doc = {}

  if type.parameters.include?(param)
    doc[:markdown] = type.attrclass(param).doc
    doc[:type] = :param
  elsif type.validproperties.include?(param)
    doc[:markdown] = type.propertybyname(param).doc
    doc[:type] = :property
  elsif type.metaparams.include?(param)
    doc[:markdown] = type.attrclass(param).doc
    doc[:type] = :meta
  end

  if type.key_attributes.include?(param) and param != :name
    doc[:type] = :namevar
  end

  doc
end

#settype(type) ⇒ Object



17
18
19
20
# File 'lib/oldskool/puppetdoc.rb', line 17

def settype(type)
  raise "Cannot find Puppet Type #{type}" unless Puppet::Type.const_defined?(type.capitalize)
  @type = Puppet::Type.const_get(type.capitalize)
end