Class: God::Behavior

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#base_name, #complain, complain, #prepare, #reset

Instance Attribute Details

#watch ⇒ Object

Returns the value of attribute watch.



7
8
9
# File 'lib/god/behavior.rb', line 7

def watch
  @watch
end

Class Method Details

.generate(kind, watch) ⇒ Object

Generate a Behavior of the given kind. The proper class is 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)



12
13
14
15
16
17
18
19
# File 'lib/god/behavior.rb', line 12

def self.generate(kind, watch)
  sym = kind.to_s.capitalize.gsub(/_(.)/) { Regexp.last_match(1).upcase }.intern
  b = God::Behaviors.const_get(sym).new
  b.watch = watch
  b
rescue NameError
  raise NoSuchBehaviorError, "No Behavior found with the class name God::Behaviors::#{sym}"
end

Instance Method Details

#after_restart ⇒ Object



36
37
# File 'lib/god/behavior.rb', line 36

def after_restart
end

#after_start ⇒ Object



30
31
# File 'lib/god/behavior.rb', line 30

def after_start
end

#after_stop ⇒ Object



42
43
# File 'lib/god/behavior.rb', line 42

def after_stop
end

#before_restart ⇒ Object



33
34
# File 'lib/god/behavior.rb', line 33

def before_restart
end

#before_start ⇒ Object



27
28
# File 'lib/god/behavior.rb', line 27

def before_start
end

#before_stop ⇒ Object



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

def before_stop
end

#friendly_name ⇒ Object

Construct the friendly name of this Behavior, looks like:

Behavior FooBar on Watch 'baz'



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

def friendly_name
  "Behavior #{super} on Watch '#{watch.name}'"
end

#valid? ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/god/behavior.rb', line 21

def valid?
  true
end