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

#watchObject

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_restartObject



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

def after_restart
end

#after_startObject



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

def after_start
end

#after_stopObject



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

def after_stop
end

#before_restartObject



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

def before_restart
end

#before_startObject



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

def before_start
end

#before_stopObject



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

def before_stop
end

#friendly_nameObject

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