summaryrefslogtreecommitdiffstats
path: root/lib/puppet/reports.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-13 14:07:24 -0500
committerLuke Kanies <luke@madstop.com>2007-10-13 14:07:24 -0500
commit29feac0cecddc910b74601d0914fa2c83757b10c (patch)
tree888305ecde1e4a488304f7e2e169bf1ca38e6d19 /lib/puppet/reports.rb
parent74d77f76a012d523430e43f1092609a4ca584cc7 (diff)
downloadpuppet-29feac0cecddc910b74601d0914fa2c83757b10c.tar.gz
puppet-29feac0cecddc910b74601d0914fa2c83757b10c.tar.xz
puppet-29feac0cecddc910b74601d0914fa2c83757b10c.zip
Translating the report handler to an indirected model.
I've provided backward compatibility with the old handler. The only terminus type that currently exists for reports is the 'code' terminus, which is used to process reports in the style of the old handler. At some point, we should likely switch at least some of these report types (e.g., 'store') to terminus types.
Diffstat (limited to 'lib/puppet/reports.rb')
-rwxr-xr-xlib/puppet/reports.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/puppet/reports.rb b/lib/puppet/reports.rb
new file mode 100755
index 000000000..df992d46c
--- /dev/null
+++ b/lib/puppet/reports.rb
@@ -0,0 +1,51 @@
+require 'puppet/util/instance_loader'
+
+# A simple mechanism for loading and returning reports.
+class Puppet::Reports
+ extend Puppet::Util::ClassGen
+ extend Puppet::Util::InstanceLoader
+
+ # Set up autoloading and retrieving of reports.
+ instance_load :report, 'puppet/reports'
+
+ class << self
+ attr_reader :hooks
+ end
+
+ # Add a new report type.
+ def self.register_report(name, options = {}, &block)
+ name = symbolize(name)
+
+ mod = genmodule(name, :extend => Puppet::Util::Docs, :hash => instance_hash(:report), :block => block)
+
+ if options[:useyaml]
+ mod.useyaml = true
+ end
+
+ mod.send(:define_method, :report_name) do
+ name
+ end
+ end
+
+ # Collect the docs for all of our reports.
+ def self.reportdocs
+ docs = ""
+
+ # Use this method so they all get loaded
+ instance_loader(:report).loadall
+ loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
+ mod = self.report(name)
+ docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
+
+ docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
+ end
+
+ docs
+ end
+
+ # List each of the reports.
+ def self.reports
+ instance_loader(:report).loadall
+ loaded_instances(:report)
+ end
+end