summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-04 16:27:35 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-07-04 16:27:35 +0000
commitc3a8d45ee644b0e7d71e62014cb65b8e8174391c (patch)
tree1c93013401e3f108b7b9512c3dca853767ec952b /lib/puppet/server
parent3c22bc944d68210881411f0c80f2252516557f5d (diff)
downloadpuppet-c3a8d45ee644b0e7d71e62014cb65b8e8174391c.tar.gz
puppet-c3a8d45ee644b0e7d71e62014cb65b8e8174391c.tar.xz
puppet-c3a8d45ee644b0e7d71e62014cb65b8e8174391c.zip
Redoing reporting a bit, so that reports are now defined as methods. If they are not methods, then they cannot use return, which makes things a bit uglier.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1359 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-xlib/puppet/server/report.rb41
1 files changed, 33 insertions, 8 deletions
diff --git a/lib/puppet/server/report.rb b/lib/puppet/server/report.rb
index 28005e636..54cb71960 100755
--- a/lib/puppet/server/report.rb
+++ b/lib/puppet/server/report.rb
@@ -20,24 +20,35 @@ class Server
]
)
- @hooks = {}
+ @reports = {}
class << self
attr_reader :hooks
end
+ def self.reportmethod(report)
+ "report_" + report.to_s
+ end
+
# Add a hook for processing reports.
def self.newreport(name, &block)
name = name.intern if name.is_a? String
- @hooks[name] = block
+ method = reportmethod(name)
+
+ # We want to define a method so that reports can use 'return'.
+ define_method(method, &block)
+
+ @reports[name] = method
end
+ # Load a report.
def self.report(name)
name = name.intern if name.is_a? String
- unless @hooks.include? name
+ unless @reports.include? reportmethod(name)
begin
require "puppet/reports/#{name}"
- unless @hooks.include? name
+ unless @reports.include? name
+ p @reports
Puppet.warning(
"Loaded report file for %s but report was not defined" %
name
@@ -54,7 +65,7 @@ class Server
end
end
- @hooks[name]
+ @reports[name]
end
def initialize(*args)
@@ -63,6 +74,19 @@ class Server
Puppet.config.use(:metrics)
end
+ # Dynamically create the report methods as necessary.
+ def method_missing(name, *args)
+ if name.to_s =~ /^report_(.+)$/
+ if self.class.report($2)
+ send(name, *args)
+ else
+ super
+ end
+ else
+ super
+ end
+ end
+
def mkclientdir(client, dir)
Puppet.config.setdefaults("reportclient-#{client}",
:clientdir => { :default => dir,
@@ -138,12 +162,13 @@ class Server
end
Puppet[:reports].split(/\s*,\s*/).each do |name|
- next unless hook = self.class.report(name)
+ method = self.class.reportmethod(name)
Puppet.info "Processing report %s" % name
-
begin
- hook.call(report)
+ send(method, report)
+ rescue NoMethodError => detail
+ Puppet.warning "No report named '%s'" % name
rescue => detail
if Puppet[:debug]
puts detail.backtrace