add info to degrading lambda, tested before and after behaviors
[god.git] / lib / god / behavior.rb
blob478e6ef2153f1ed44c7d49b23632f744dad7168e
1 module God
2   
3   class Behavior
4     include Configurable
5     
6     attr_accessor :watch
7     
8     # Generate a Behavior of the given kind. The proper class is found by camel casing the
9     # kind (which is given as an underscored symbol).
10     #   +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
11     def self.generate(kind, watch)
12       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
13       b = God::Behaviors.const_get(sym).new
14       b.watch = watch
15       b
16     rescue NameError
17       raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}")
18     end
19     
20     def valid?
21       true
22     end
23         
24     #######
25     
26     def before_start
27     end
28     
29     def after_start
30     end
31     
32     def before_restart
33     end
34     
35     def after_restart
36     end
37     
38     def before_stop
39     end
40     
41     def after_stop
42     end
43     
44     # Construct the friendly name of this Behavior, looks like:
45     #
46     # Behavior FooBar on Watch 'baz'
47     def friendly_name
48       "Behavior " + super + " on Watch '#{self.watch.name}'"
49     end
50   end
51   
52 end