revamped some tests
[god.git] / lib / god / behavior.rb
blob630b4590f9cdf05d2a13c9d7f1640dc9dc923fd7
1 module God
2   
3   class Behavior < Base
4     # Generate a Behavior of the given kind. The proper class if found by camel casing the
5     # kind (which is given as an underscored symbol).
6     #   +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
7     def self.generate(kind)
8       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
9       God::Behaviors.const_get(sym).new
10     rescue NameError
11       raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}")
12     end
13     
14     # Override this method in your Behaviors (optional)
15     #
16     # Called once after the Condition has been sent to the block and attributes have been
17     # set. Do any post-processing on attributes here
18     def prepare
19       
20     end
21     
22     # Override this method in your Behaviors (optional)
23     #
24     # Called once during evaluation of the config file. Return true if valid, false otherwise
25     #
26     # A convenience method 'complain' is available that will print out a message and return false,
27     # making it easy to report multiple validation errors:
28     #
29     #   def valid?
30     #     valid = true
31     #     valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
32     #     valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
33     #     valid
34     #   end
35     def valid?
36       true
37     end
38     
39     #######
40     
41     def before_start
42     end
43     
44     def after_start
45     end
46     
47     def before_restart
48     end
49     
50     def after_restart
51     end
52     
53     def before_stop
54     end
55     
56     def after_stop
57     end
58     
59     protected
60     
61     def complain(text)
62       puts text
63       false
64     end
65   end
66   
67 end