Class: Daemon::Supervision::Definition
- Inherits:
-
Object
- Object
- Daemon::Supervision::Definition
- Includes:
- Enumerable
- Defined in:
- lib/onapp/engine/supervision/definition.rb,
lib/onapp/engine/supervision/definition/handler.rb
Defined Under Namespace
Classes: Handler
Constant Summary
- DEFAULT_GROUP =
'_default'
Instance Attribute Summary (collapse)
-
- (Object) groups_to_run
readonly
Returns the value of attribute groups_to_run.
Instance Method Summary (collapse)
- - (Object) add(supervisor, runner, opts = {})
- - (Object) each(&block)
- - (Object) group(name)
- - (Object) group_names
- - (Object) groups
- - (Object) handlers (also: #all)
- - (Object) handlers_to_run
-
- (Definition) initialize(&block)
constructor
A new instance of Definition.
Constructor Details
- (Definition) initialize(&block)
Returns a new instance of Definition
12 13 14 15 16 17 |
# File 'lib/onapp/engine/supervision/definition.rb', line 12 def initialize(&block) @groups = Hash.new { |h,k| h[k] = [] } @groups_to_run = [] @group = DEFAULT_GROUP instance_eval(&block) if block end |
Instance Attribute Details
- (Object) groups_to_run (readonly)
Returns the value of attribute groups_to_run
8 9 10 |
# File 'lib/onapp/engine/supervision/definition.rb', line 8 def groups_to_run @groups_to_run end |
Instance Method Details
- (Object) add(supervisor, runner, opts = {})
40 41 42 43 44 |
# File 'lib/onapp/engine/supervision/definition.rb', line 40 def add(supervisor, runner, opts = {}) handler = Handler.new(supervisor, runner, opts) @groups[@group] << handler handler end |
- (Object) each(&block)
46 47 48 |
# File 'lib/onapp/engine/supervision/definition.rb', line 46 def each(&block) handlers_to_run.each(&block) end |
- (Object) group(name)
50 51 52 53 54 |
# File 'lib/onapp/engine/supervision/definition.rb', line 50 def group(name) old, @group = @group, name yield @group = old end |
- (Object) group_names
36 37 38 |
# File 'lib/onapp/engine/supervision/definition.rb', line 36 def group_names groups.keys end |
- (Object) groups
32 33 34 |
# File 'lib/onapp/engine/supervision/definition.rb', line 32 def groups @groups.dup end |
- (Object) handlers Also known as: all
27 28 29 |
# File 'lib/onapp/engine/supervision/definition.rb', line 27 def handlers groups.values.flatten.uniq end |
- (Object) handlers_to_run
19 20 21 22 23 24 25 |
# File 'lib/onapp/engine/supervision/definition.rb', line 19 def handlers_to_run if groups_to_run.any? groups.values_at(*groups_to_run).flatten else handlers end end |