extracted behavior code
[god.git] / lib / god / behavior.rb
blobddc18ddfe721ac9c7fba8eaadc6eefcc673d23da
1 module God
2   
3   class Behavior < Base
4     def self.generate(kind)
5       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
6       God::Behaviors.const_get(sym).new
7     rescue NameError
8       raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{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     #######
28     
29     def before_start
30     end
31     
32     def after_start
33     end
34     
35     def before_restart
36     end
37     
38     def after_restart
39     end
40     
41     def before_stop
42     end
43     
44     def after_stop
45     end
46     
47     protected
48     
49     def complain(text)
50       puts text
51       false
52     end
53   end
54   
55 end