Class: God::Behavior
- Inherits:
-
Object
- Object
- God::Behavior
- Defined in:
- lib/god/behavior.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#watch ⇒ Object
Returns the value of attribute watch.
Class Method Summary collapse
-
.generate(kind, watch) ⇒ Object
Generate a Behavior of the given kind.
Instance Method Summary collapse
- #after_restart ⇒ Object
- #after_start ⇒ Object
- #after_stop ⇒ Object
- #before_restart ⇒ Object
- #before_start ⇒ Object
- #before_stop ⇒ Object
-
#prepare ⇒ Object
Override this method in your Behaviors (optional).
-
#valid? ⇒ Boolean
Override this method in your Behaviors (optional).
Instance Attribute Details
#watch ⇒ Object
Returns the value of attribute watch.
4 5 6 |
# File 'lib/god/behavior.rb', line 4 def watch @watch end |
Class Method Details
.generate(kind, watch) ⇒ Object
Generate a Behavior of the given kind. The proper class if found by camel casing the kind (which is given as an underscored symbol).
+kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Behaviors::FooBar)
9 10 11 12 13 14 15 16 |
# File 'lib/god/behavior.rb', line 9 def self.generate(kind, watch) sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern b = God::Behaviors.const_get(sym).new b.watch = watch b rescue NameError raise NoSuchBehaviorError.new("No Behavior found with the class name God::Behaviors::#{sym}") end |
Instance Method Details
#after_restart ⇒ Object
54 55 |
# File 'lib/god/behavior.rb', line 54 def after_restart end |
#after_start ⇒ Object
48 49 |
# File 'lib/god/behavior.rb', line 48 def after_start end |
#after_stop ⇒ Object
60 61 |
# File 'lib/god/behavior.rb', line 60 def after_stop end |
#before_restart ⇒ Object
51 52 |
# File 'lib/god/behavior.rb', line 51 def before_restart end |
#before_start ⇒ Object
45 46 |
# File 'lib/god/behavior.rb', line 45 def before_start end |
#before_stop ⇒ Object
57 58 |
# File 'lib/god/behavior.rb', line 57 def before_stop end |
#prepare ⇒ Object
Override this method in your Behaviors (optional)
Called once after the Condition has been sent to the block and attributes have been set. Do any post-processing on attributes here
22 23 24 |
# File 'lib/god/behavior.rb', line 22 def prepare end |
#valid? ⇒ Boolean
Override this method in your Behaviors (optional)
Called once during evaluation of the config file. Return true if valid, false otherwise
A convenience method ‘complain’ is available that will print out a message and return false, making it easy to report multiple validation errors:
def valid?
valid = true
valid &= complain("You must specify the 'pid_file' attribute for :memory_usage") if self.pid_file.nil?
valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil?
valid
end
39 40 41 |
# File 'lib/god/behavior.rb', line 39 def valid? true end |