added MemoryUsage and factored out ProcessCondition
[god.git] / lib / god / condition.rb
blob0f68ba9007f6f4ba4deae2e0e4931af5c55ddf6e
1 module God
2   
3   class Condition < Base
4     def self.generate(kind)
5       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
6       God::Conditions.const_get(sym).new
7     rescue NameError
8       raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}")
9     end
10     
11     # Override this method in your Conditions (optional)
12     #
13     # Called once after the Condition has been sent to the block and attributes have been
14     # set. Do any post-processing on attributes here
15     def prepare
16       
17     end
18     
19     # Override this method in your Conditions (optional)
20     #
21     # Called once during evaluation of the config file.
22     # If invalid attributes are found, use #complain('text') to print out the error message
23     def valid?
24       true
25     end
26     
27     # Override this method in your Conditions (optional)
28     def before
29     end
30     
31     # Override this method in your Conditions (mandatory)
32     #
33     # Return true if the test passes (everything is ok)
34     # Return false otherwise
35     def test
36       raise AbstractMethodNotOverriddenError.new("Condition#test must be overridden in subclasses")
37     end
38     
39     # Override this method in your Conditions (optional)
40     def after
41     end
42     
43     #######
44     
45     def before_start
46     end
47     
48     def after_start
49     end
50     
51     def before_restart
52     end
53     
54     def after_restart
55     end
56     
57     def before_stop
58     end
59     
60     def after_stop
61     end
62     
63     protected
64     
65     def complain(text)
66       puts text
67       false
68     end
69   end
70   
71 end