Add comments to Timer
[god.git] / lib / god / configurable.rb
blobaa35158fedf1729f5212b6df5b9fc344894e796b
1 module God
2   
3   module Configurable
4     # Override this method in your Configurable (optional)
5     #
6     # Called once after the Configurable has been sent to the block and attributes have been
7     # set. Do any post-processing on attributes here
8     def prepare
9       
10     end
11     
12     def reset
13       
14     end
15     
16     # Override this method in your Configurable (optional)
17     #
18     # Called once during evaluation of the config file. Return true if valid, false otherwise
19     #
20     # A convenience method 'complain' is available that will print out a message and return false,
21     # making it easy to report multiple validation errors:
22     #
23     #   def valid?
24     #     valid = true
25     #     valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
26     #     valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
27     #     valid
28     #   end
29     def valid?
30       true
31     end
32     
33     def base_name
34       self.class.name.split('::').last
35     end
36     
37     def friendly_name
38       base_name
39     end
40     
41     def self.complain(text, c = nil)
42       watch = c.watch rescue nil
43       msg = ""
44       msg += "#{watch.name}: " if watch
45       msg += text
46       msg += " for #{c.friendly_name}" if c
47       applog(watch, :error, msg)
48       false
49     end
50     
51     def complain(text, c = nil)
52       Configurable.complain(text, c)
53     end
54   end
55   
56 end