module Lita::Registry::Mixins

Allows a registry to be added to another object.

Public Instance Methods

adapters() click to toggle source

A registry of adapters. @return [Hash] A map of adapter keys to adapter classes.

# File lib/lita/registry.rb, line 22
def adapters
  @adapters ||= {}
end
clear_config()
Alias for: reset_config
config() click to toggle source

The primary configuration object. Provides user settings for the robot. @return [Lita::Configuration] The configuration object.

# File lib/lita/registry.rb, line 9
def config
  @config ||= DefaultConfiguration.new(self).build
end
configure() { |config| ... } click to toggle source

Yields the configuration object. Called by the user in a lita_config.rb file. @yieldparam [Lita::Configuration] config The configuration object. @return [void]

# File lib/lita/registry.rb, line 16
def configure
  yield config
end
handlers() click to toggle source

A registry of handlers. @return [Set] The set of handlers.

# File lib/lita/registry.rb, line 28
def handlers
  @handlers ||= Set.new
end
hooks() click to toggle source

A registry of hook handler objects. @return [Hash] A hash mapping hook names to sets of objects that handle them. @since 3.2.0

# File lib/lita/registry.rb, line 35
def hooks
  @hooks ||= Hash.new { |h, k| h[k] = Set.new }
end
register_adapter(key, adapter = nil, &block) click to toggle source

@overload #register_adapter(key, adapter)

Adds an adapter to the registry under the provided key.
@param key [String, Symbol] The key that identifies the adapter.
@param adapter [Class] The adapter class.
@return [void]

@overload #register_adapter(key)

Adds an adapter to the registry under the provided key.
@param key [String, Symbol] The key that identifies the adapter.
@yield The body of the adapter class.
@return [void]
@since 4.0.0
# File lib/lita/registry.rb, line 50
def register_adapter(key, adapter = nil, &block)
  adapter = PluginBuilder.new(key, &block).build_adapter if block

  unless adapter.is_a?(Class)
    raise ArgumentError, I18n.t("lita.core.register_adapter.block_or_class_required")
  end

  adapters[key.to_sym] = adapter
end
register_handler(handler_or_key, &block) click to toggle source

@overload #register_handler(handler)

Adds a handler to the registry.
@param handler [Lita::Handler] The handler class.
@return [void]

@overload #register_handler(key)

Adds a handler to the registry.
@param key [String] The namespace of the handler.
@yield The body of the handler class.
@return [void]
@since 4.0.0
# File lib/lita/registry.rb, line 70
def register_handler(handler_or_key, &block)
  if block
    handler = PluginBuilder.new(handler_or_key, &block).build_handler
  else
    handler = handler_or_key

    unless handler.is_a?(Class)
      raise ArgumentError, I18n.t("lita.core.register_handler.block_or_class_required")
    end
  end

  handlers << handler
end
register_hook(name, hook) click to toggle source

Adds a hook handler object to the registry for the given hook. @return [void] @since 3.2.0

# File lib/lita/registry.rb, line 87
def register_hook(name, hook)
  hooks[name.to_s.downcase.strip.to_sym] << hook
end
reset() click to toggle source

Clears the configuration object and the adapter, handler, and hook registries. @return [void] @since 3.2.0

# File lib/lita/registry.rb, line 94
def reset
  reset_adapters
  reset_config
  reset_handlers
  reset_hooks
end
reset_adapters() click to toggle source

Resets the adapter registry, removing all registered adapters. @return [void] @since 3.2.0

# File lib/lita/registry.rb, line 104
def reset_adapters
  @adapters = nil
end
reset_config() click to toggle source

Resets the configuration object. The next call to {#config} will create a fresh config object. @return [void]

# File lib/lita/registry.rb, line 111
def reset_config
  @config = nil
end
Also aliased as: clear_config
reset_handlers() click to toggle source

Resets the handler registry, removing all registered handlers. @return [void] @since 3.2.0

# File lib/lita/registry.rb, line 119
def reset_handlers
  @handlers = nil
end
reset_hooks() click to toggle source

Resets the hooks registry, removing all registered hook handlers. @return [void] @since 3.2.0

# File lib/lita/registry.rb, line 126
def reset_hooks
  @hooks = nil
end