Class: God::Behavior

Inherits:
Object
  • Object
show all
Defined in:
lib/god/behavior.rb

Direct Known Subclasses

God::Behaviors::CleanPidFile, Condition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#watchObject

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_restartObject



54
55
# File 'lib/god/behavior.rb', line 54

def after_restart
end

#after_startObject



48
49
# File 'lib/god/behavior.rb', line 48

def after_start
end

#after_stopObject



60
61
# File 'lib/god/behavior.rb', line 60

def after_stop
end

#before_restartObject



51
52
# File 'lib/god/behavior.rb', line 51

def before_restart
end

#before_startObject



45
46
# File 'lib/god/behavior.rb', line 45

def before_start
end

#before_stopObject



57
58
# File 'lib/god/behavior.rb', line 57

def before_stop
end

#prepareObject

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

Returns:

  • (Boolean)


39
40
41
# File 'lib/god/behavior.rb', line 39

def valid?
  true
end