diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-28 16:30:49 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-08-28 16:30:49 +0000 |
commit | d45d22b7547a608c7821905024f530bbae1259d7 (patch) | |
tree | 018f311b26a7854271524beba90a778918bd7ee6 /lib | |
parent | e1aff4cd2f456bfc9567e9be5dd73b3c8ed14ec9 (diff) | |
download | puppet-d45d22b7547a608c7821905024f530bbae1259d7.tar.gz puppet-d45d22b7547a608c7821905024f530bbae1259d7.tar.xz puppet-d45d22b7547a608c7821905024f530bbae1259d7.zip |
Adding a module specifically for making doc generation easier, and adding defaults info to provider docs.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1504 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/provider.rb | 24 | ||||
-rw-r--r-- | lib/puppet/util.rb | 1 | ||||
-rw-r--r-- | lib/puppet/util/classgen.rb | 1 | ||||
-rw-r--r-- | lib/puppet/util/docs.rb | 27 | ||||
-rw-r--r-- | lib/puppet/util/metaid.rb | 7 |
5 files changed, 47 insertions, 13 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index 1aff6b9fc..57dfc8409 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -6,7 +6,7 @@ class Puppet::Provider class << self # Include the util module so we have access to things like 'binary' - include Puppet::Util + include Puppet::Util, Puppet::Util::Docs attr_accessor :name, :model attr_writer :doc end @@ -34,6 +34,7 @@ class Puppet::Provider def self.commands(hash) hash.each do |name, path| name = symbolize(name) + @origcommands[name] = path # Keep the short name if we couldn't find it. unless path =~ /^\// if tmp = binary(path) @@ -77,25 +78,26 @@ class Puppet::Provider @defaults.length end - # Specify a documentation string. - def self.desc(str) - @doc = str + dochook(:defaults) do + if @defaults.length > 0 + return " Default for " + @defaults.collect do |f, v| + "``#{f}`` == ``#{v}``" + end.join(" and ") + "." + end end - def self.doc - if defined? @commands and @commands.length > 0 - extra = " Required binaries: " + @commands.collect do |n, c| + dochook(:commands) do + if @origcommands.length > 0 + return " Required binaries: " + @origcommands.collect do |n, c| "``#{c}``" - end.join(", ") - @doc + extra - else - @doc + end.join(", ") + "." end end def self.initvars @defaults = {} @commands = {} + @origcommands = {} @confines = Hash.new do |hash, key| hash[key] = [] end diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 3fc0be91d..3352974e0 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -510,5 +510,6 @@ end require 'puppet/util/methodhelper' require 'puppet/util/metaid' require 'puppet/util/classgen' +require 'puppet/util/docs' # $Id$ diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb index c09fe5ae0..d7622cf93 100644 --- a/lib/puppet/util/classgen.rb +++ b/lib/puppet/util/classgen.rb @@ -4,7 +4,6 @@ module Puppet end module Puppet::Util::ClassGen - include Puppet::Util::MetaID include Puppet::Util::MethodHelper include Puppet::Util diff --git a/lib/puppet/util/docs.rb b/lib/puppet/util/docs.rb new file mode 100644 index 000000000..2fccd4abc --- /dev/null +++ b/lib/puppet/util/docs.rb @@ -0,0 +1,27 @@ +# Some simple methods for helping manage automatic documentation generation. +module Puppet::Util::Docs + # Specify the actual doc string. + def desc(str) + @doc = str + end + + # Add a new autodoc block. We have to define these as class methods, + # rather than just sticking them in a hash, because otherwise they're + # too difficult to do inheritance with. + def dochook(name, &block) + method = "dochook_" + name.to_s + + meta_def method, &block + end + + # Generate the full doc string. + def doc + extra = methods.find_all { |m| m.to_s =~ /^dochook_.+/ }.collect { |m| + self.send(m) + }.join(" ") + + @doc + extra + end +end + +# $Id$ diff --git a/lib/puppet/util/metaid.rb b/lib/puppet/util/metaid.rb index 7054989db..0978e7b32 100644 --- a/lib/puppet/util/metaid.rb +++ b/lib/puppet/util/metaid.rb @@ -1,4 +1,4 @@ -module Puppet::Util::MetaID +class Object # The hidden singleton lurks behind everyone def metaclass; class << self; self; end; end def meta_eval(&blk); metaclass.instance_eval(&blk); end @@ -8,6 +8,11 @@ module Puppet::Util::MetaID meta_eval { define_method name, &blk } end + # Remove metaclass methods. + def meta_undef(name, &blk) + meta_eval { remove_method name } + end + # Defines an instance method within a class def class_def(name, &blk) class_eval { define_method name, &blk } |