Class: Celluloid::Supervision::Configuration

### Home Classes Methods

### In Files

- lib/celluloid/supervision/configuration.rb
- lib/celluloid/supervision/configuration/injections.rb
- lib/celluloid/supervision/configuration/instance.rb
- lib/celluloid/supervision/constants.rb
- lib/celluloid/supervision/deprecate/validation.rb
- lib/celluloid/supervision/validation.rb

### Parent

Object

### Namespace

- MODULE Celluloid::Supervision::Configuration::Error
- CLASS Celluloid::Supervision::Configuration::Injection
- CLASS Celluloid::Supervision::Configuration::Instance

### Methods

- ::alias!
- ::aliases
- ::arity
- ::arity!
- ::define
- ::deploy
- ::new
- ::options
- ::parameter!
- ::parameters
- ::parse
- ::resync_parameters
- ::save_defaults
- ::valid?
- #add
- #another
- #count
- #define
- #deploy
- #each
- #export
- #include?
- #increment
- #merge
- #merge!
- #provider
- #resync_accessors
- #shutdown

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::ClassMethods
- Celluloid::Supervision
- Celluloid::Supervision::Configuration
- Celluloid::Supervision::Configuration::Error
- Celluloid::Supervision::Configuration::Error::AlreadyDefined
- Celluloid::Supervision::Configuration::Error::Incomplete
- Celluloid::Supervision::Configuration::Error::Invalid
- Celluloid::Supervision::Configuration::Error::InvalidSupervisor
- Celluloid::Supervision::Configuration::Error::InvalidValues
- Celluloid::Supervision::Configuration::Injection
- Celluloid::Supervision::Configuration::Instance
- Celluloid::Supervision::Container
- Celluloid::Supervision::Container::Behavior
- Celluloid::Supervision::Container::Behavior::ClassMethods
- Celluloid::Supervision::Container::Behavior::Error
- Celluloid::Supervision::Container::Behavior::Error::Mutant
- Celluloid::Supervision::Container::Injection
- Celluloid::Supervision::Container::Instance
- Celluloid::Supervision::Container::Tree
- Celluloid::Supervision::Error
- Celluloid::Supervision::Error::NoPublicService
- Celluloid::Supervision::Service
- Celluloid::Supervision::Service::Public
- Celluloid::Supervision::Service::Root
- Celluloid::Supervisor

No matching classes.

# Celluloid::Supervision::Configuration

### Constants

INJECTIONS
REMOVE_AT_EXPORT

  These are applied inside Supervision::Member ################

### Attributes

instances[RW]

### Public Class Methods

alias!(aliased, original) click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 94
    def alias!(aliased, original)
      @@aliases[aliased] = original
    end

aliases() click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 90
    def aliases
      @@aliases
    end

arity() click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 82
    def arity
      @@arity
    end

arity!(key, value) click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 86
    def arity!(key, value)
      @@arity[key] = value
    end

define(options={}) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 9
    def define(options={})
      new(options)
    end

deploy(options={}) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 5
    def deploy(options={})
      define(options).deploy
    end

new(options={}) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 28
    def initialize(options={})
      @instances = [Instance.new]
      @branch = :services
      @i = 0 # incrementer of instances in this branch
      resync_accessors
      @configuration = options

      if options.is_a? Hash
        options[:configuration] ||= Container::Behavior.configure(options)
        @configuration = instance_eval(&options[:configuration])
        @supervisor ||= @configuration.fetch(:supervisor, :"Celluloid.services")
      end
      @supervisor ||= :"Celluloid.services"

      if (@configuration.is_a?(Hash) || @configuration.is_a?(Array)) && @configuration.any?
        define(@configuration)
      end
    end

options(args, options={}) click to toggle source

    # File lib/celluloid/supervision/deprecate/validation.rb, line 40
    def options(args, options={})
      return args.merge!(options) if args.is_a? Configuration::Instance
      # Not a Supervision:Configuration?
      # Try to guess its structure and build one:
      options = parse(args).merge(options)
      options[:configuration] = Container::Behavior.configure(options)
      options[:args].compact! if options[:args].is_a? Array
      options.select! { |k, v| !v.nil? }
      Configuration.valid? options, true
      options
    end

parameter!(key, value) click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 78
    def parameter!(key, value)
      @@parameters[key] << value unless @@parameters[key].include? value
    end

parameters(*args) click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 74
    def parameters(*args)
      args.inject([]) { |parameters, p| parameters += @@parameters[p]; parameters }
    end

parse(args) click to toggle source

    # File lib/celluloid/supervision/deprecate/validation.rb, line 12
    def parse(args)
      return args if args.is_a? Configuration::Instance
      options = {args: []}
      return {type: args} if args.is_a? Class
      if args.is_a? Hash
        return args
      elsif args.is_a? Array
        if args.length == 1
          return args[0] if args.first.is_a? Configuration::Instance
          return {type: args.first} if args.first.is_a? Class
          if args.first.is_a?(Hash) && args = args.pop
            return args
          end
          options[:args] = args if args.any?
        elsif args.length > 1
          # TODO: don't use each
          options.merge! args.pop if args.last.is_a? Hash
          options[:type] = args.shift if args.first.is_a? Class
          options[:args] += args if args.any?
        end
      end
      options
    end

resync_parameters() click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 68
    def resync_parameters
      @@parameters = @@defaults[:parameters].inject({}) { |p, (k, v)| p[k] = v.dup; p }
      @@aliases = @@defaults[:aliases].dup
      @@arity = @@defaults[:arity].dup
    end

save_defaults() click to toggle source

    # File lib/celluloid/supervision/constants.rb, line 60
    def save_defaults
      @@defaults = {
        parameters: @@parameters.inject({}) { |p, (k, v)| p[k] = v.dup; p },
        aliases: @@aliases.dup,
        arity: @@arity.dup,
      }
    end

valid?(configuration, fails=false) click to toggle source

    # File lib/celluloid/supervision/validation.rb, line 5
    def valid?(configuration, fails=false)
      parameters(:mandatory).each do |k|
        unless configuration.key? k
          if fails
            fail Error::Incomplete, "Missing `:#{k}` in supervision configuration."
          else
            return false
          end
        end
      end
      arity.each do |klass, args|
        unless configuration[args].is_a? Proc
          __a = configuration[args] && configuration[args].count || 0
          __arity = configuration[klass].allocate.method(:initialize).arity
          unless (__arity < 0 && __a >= __arity.abs-1) || __a == __arity.abs
            if fails
              fail ArgumentError.new("#{__a} vs. #{__arity}")
            else
              return false
            end
          end
        end
      end
      true
    end

### Public Instance Methods

add(options) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 151
    def add(options)
      define(options)
      provider.supervise options if Configuration.valid? options
    end

another() click to toggle source
Alias for: increment
count() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 70
    def count
      @instances.count
    end

define(configuration, fail=false) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 130
    def define(configuration, fail=false)
      if configuration.is_a? Array
        configuration.each { |c| define(c, fail) }
      else
        unless include? configuration[:as]
          begin
            current_instance.define(configuration, fail)
          rescue Error::AlreadyDefined
            increment
            retry
          end
        end
      end
      self
    end

deploy(options={}) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 62
    def deploy(options={})
      define(options) if options.any?
      @instances.each do |instance|
        provider.add instance.merge(branch: @branch)
      end
      provider
    end

each(&block) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 74
    def each(&block)
      @instances.each(&block)
    end

export() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 121
    def export
      return current_instance.to_hash if @i == 0
      @instances.map(&:export)
    end

include?(name) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 126
    def include?(name)
      @instances.map(&:name).include? name
    end

increment() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 146
    def increment
      @i += 1
    end

Also aliased as: another
merge(values) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 113
    def merge(values)
      if values.is_a?(Configuration) || values.is_a?(Hash)
        current_instance.merge(values)
      else
        fail Error::Invalid
      end
    end

merge!(values) click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 105
    def merge!(values)
      if values.is_a?(Configuration) || values.is_a?(Hash)
        current_instance.merge!(values)
      else
        fail Error::Invalid
      end
    end

provider() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 47
    def provider
      @provider ||= if @supervisor.is_a? Hash
                      @supervisor[:type].run!(@supervisor)
                    elsif @supervisor.is_a? Symbol
                      @supervisor = Object.module_eval(@supervisor.to_s)
                      provider
                    elsif @supervisor.is_a? Class
                      @supervisor.run!
                    elsif @supervisor.respond_to? :supervise
                      @supervisor
                    else
                      fail Error::InvalidSupervisor
                    end
    end

resync_accessors() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 78
    def resync_accessors
      # methods for setting and getting the usual defaults
      Configuration.parameters(:mandatory, :optional, :plugins, :meta).each do |key|
        [:"#{key}!", :"#{key}="].each do |m|
          self.class.instance_eval do
            remove_method :"#{m}" rescue nil # avoid warnings in tests
            define_method(m) { |p| current_instance.send(m, p) }
          end
        end
        [:"#{key}?", :"#{key}"].each do |m|
          self.class.instance_eval do
            remove_method :"#{m}" rescue nil # avoid warnings in tests
            define_method(m) { current_instance.send(m) }
          end
        end
      end

      Configuration.aliases.each do |_alias, _original|
        ["!", :"=", :"?", :""]. each do |m|
          self.class.instance_eval do
            remove_method :"#{_alias}#{m}" rescue nil # avoid warnings in tests
            alias_method :"#{_alias}#{m}", :"#{_original}#{m}"
          end
        end
      end
    end

shutdown() click to toggle source

    # File lib/celluloid/supervision/configuration.rb, line 156
    def shutdown
      @provider.shutdown
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.