Module: Celluloid::Supervision::Container::Behavior

Included in:
Pool, Tree
Defined in:
lib/celluloid/supervision/container/behavior.rb

Defined Under Namespace

Modules: ClassMethods, Error

Constant Summary collapse

@@injections =

Hash of Class => Hash of Injections

{}
@@behaviors =

Hash of identifying symbol parameter => Class

{}

Class Method Summary collapse

Class Method Details

.[](identifier) ⇒ Object


21
22
23
# File 'lib/celluloid/supervision/container/behavior.rb', line 21

def [](identifier)
  @@behaviors[identifier]
end

.[]=(identifier, behavior) ⇒ Object


25
26
27
# File 'lib/celluloid/supervision/container/behavior.rb', line 25

def []=(identifier, behavior)
  @@behaviors[identifier] = behavior
end

.configure(options) ⇒ Object

Beware of order. There may be multiple behavior injections, but their order is not determined ( yet ) Right now, something like a pool-coordinator-tree supervisor mutant are absolutely expected to crash. Therefore, sorry Professor X – we kill every Mutant. On sight, no questions asked. Zero mutant love.


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/celluloid/supervision/container/behavior.rb', line 45

def configure(options)
  behavior = nil
  injection = nil
  @@behaviors.map do |identifier, injector|
    if identifier = parameter(identifier, options)
      if behavior
        raise Error::Mutant, "More than one type of behavior expected."
      else
        if @@injections[injector].include?(:configuration)
          injection = @@injections[behavior = injector][:configuration]
          options[:behavior] ||= behavior
        end
      end
    end
  end

  options[:type] ||= behavior
  injection || proc { @configuration }
end

.included(klass) ⇒ Object


13
14
15
# File 'lib/celluloid/supervision/container/behavior.rb', line 13

def included(klass)
  klass.send :extend, ClassMethods
end

.injectionsObject


17
18
19
# File 'lib/celluloid/supervision/container/behavior.rb', line 17

def injections
  @@injections
end

.parameter(identifier, options) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/celluloid/supervision/container/behavior.rb', line 29

def parameter(identifier, options)
  found = nil
  p = Configuration.aliases.each_with_object([identifier]) { |(a, i), invoke| invoke << a if i == identifier; }
  case p.count { |parameter| found = parameter; options.key?(parameter) }
  when 1
    found
  when 0

  else
    raise Error::Mutant, "More than one kind of identifiable behavior parameter."
  end
end