Module: PuppetStrings::Describe
- Defined in:
- lib/puppet-strings/describe.rb
Overview
The module for command line documentation related functionality.
Class Method Summary collapse
- .list_one_type(type) ⇒ Object
-
.render(describe_types = [], list = false, providers = false) ⇒ void
Renders requested types or a summarized list in the current YARD registry to STDOUT.
- .show_one_parameter(parameter) ⇒ Object
- .show_one_type(resource_type, providers = false) ⇒ Object
Class Method Details
.list_one_type(type) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet-strings/describe.rb', line 56 def self.list_one_type(type) targetlength = 48 shortento = targetlength - 4 contentstring = type[:docstring][:text] end_of_line = contentstring.index("\n") # "." gives closer results to old describeb, but breaks for '.k5login' if !end_of_line.nil? contentstring = contentstring[0..end_of_line] end if contentstring.length > targetlength contentstring = contentstring[0..shortento] + ' ...' end puts "%-15s - %-s" % [type[:name], contentstring] end |
.render(describe_types = [], list = false, providers = false) ⇒ void
This method returns an undefined value.
Renders requested types or a summarized list in the current YARD registry to STDOUT.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet-strings/describe.rb', line 13 def self.render(describe_types = [], list = false, providers = false) document = { defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash), resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash), } if list puts "These are the types known to puppet:" document[:resource_types].each { |t| list_one_type(t) } else document[:providers] = YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash) type_names = {} describe_types.each { |name| type_names[name] = true } document[:resource_types].each do |t| show_one_type(t, providers) if type_names[t[:name].to_s] end end end |
.show_one_parameter(parameter) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/puppet-strings/describe.rb', line 49 def self.show_one_parameter(parameter) puts "\n- **%{name}**\n" % { name: parameter[:name] } puts parameter[:description] puts "Valid values are `%{values}`." % { values: parameter[:values].join("`, `") } unless parameter[:values].nil? puts "Requires features %{required_features}." % { required_features: parameter[:required_features] } unless parameter[:required_features].nil? end |
.show_one_type(resource_type, providers = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet-strings/describe.rb', line 34 def self.show_one_type(resource_type, providers = false) puts "\n%{name}\n%{underscore}" % { name: resource_type[:name], underscore: "=" * resource_type[:name].length } puts resource_type[:docstring][:text] combined_list = (resource_type[:parameters].nil? ? [] : resource_type[:parameters]) + (resource_type[:properties].nil? ? [] : resource_type[:properties]) if combined_list.any? puts "\nParameters\n----------" combined_list.sort_by { |p| p[:name] }.each { |p| show_one_parameter(p) } puts "\nProviders\n---------" end #Show providers here - list or provide details end |