module Lita

The main namespace for Lita. Provides a global registry of adapters and handlers, as well as global configuration, logger, and Redis store.

Constants

REDIS_NAMESPACE

The base Redis namespace for all Lita data.

VERSION

The current version of Lita.

Attributes

test_mode[RW]

A mode that makes minor changes to the Lita runtime to improve testability. @return [Boolean] Whether or not test mode is active. @since 4.0.0

test_mode?[RW]

A mode that makes minor changes to the Lita runtime to improve testability. @return [Boolean] Whether or not test mode is active. @since 4.0.0

version_3_compatibility_mode[RW]

A special mode to ensure that tests written for Lita 3 plugins continue to work. @return [Boolean] Whether or not version 3 compatibility mode is active. @since 4.0.0

version_3_compatibility_mode?[RW]

A special mode to ensure that tests written for Lita 3 plugins continue to work. @return [Boolean] Whether or not version 3 compatibility mode is active. @since 4.0.0

Public Class Methods

default_locale=(new_locale) click to toggle source

Sets I18n.default_locale, normalizing the provided locale name.

This is preferred over {Lita#locale=} as it affects all threads. @param new_locale [Symbol, String] The code of the locale to use. @return [void] @since 4.8.0

# File lib/lita/common.rb, line 34
def default_locale=(new_locale)
  I18n.default_locale = new_locale.to_s.tr("_", "-")
end
load_locales(paths) click to toggle source

Adds one or more paths to the I18n load path and reloads I18n. @param paths [String, Array<String>] The path(s) to add. @return [void] @since 3.0.0

# File lib/lita/common.rb, line 10
def load_locales(paths)
  I18n.load_path.concat(Array(paths))
  I18n.reload!
end
locale=(new_locale) click to toggle source

Sets I18n.locale, normalizing the provided locale name.

Note that setting this only affects the current thread. Since handler methods are dispatched in new threads, changing the locale globally will require calling this method at the start of every handler method. Alternatively, use {Lita#default_locale=} which will affect all threads. @param new_locale [Symbol, String] The code of the locale to use. @return [void] @since 3.0.0

# File lib/lita/common.rb, line 24
def locale=(new_locale)
  I18n.locale = new_locale.to_s.tr("_", "-")
end
logger() click to toggle source

The global Logger object. @return [::Logger] The global Logger object.

# File lib/lita.rb, line 42
def logger
  @logger ||= Logger.get_logger(config.robot.log_level, config.robot.log_formatter)
end
redis() click to toggle source

The root Redis object. @return [Redis::Namespace] The root Redis object.

# File lib/lita.rb, line 48
def redis
  @redis ||= begin
    redis = Redis.new(config.redis)
    Redis::Namespace.new(REDIS_NAMESPACE, redis: redis).tap do |client|
      begin
        client.ping
      rescue Redis::BaseError => e
        if Lita.test_mode?
          raise RedisError, I18n.t("lita.redis.test_mode_exception", message: e.message)
        else
          Lita.logger.fatal I18n.t(
            "lita.redis.exception",
            message: e.message,
            backtrace: e.backtrace.join("\n")
          )
          abort
        end
      end
    end
  end
end
run(config_path = nil) click to toggle source

Loads user configuration and starts the robot. @param config_path [String] The path to the user configuration file. @return [void]

# File lib/lita.rb, line 73
def run(config_path = nil)
  hooks[:before_run].each { |hook| hook.call(config_path: config_path) }
  ConfigurationBuilder.load_user_config(config_path)
  ConfigurationBuilder.freeze_config(config)
  ConfigurationValidator.new(self).call
  hooks[:config_finalized].each { |hook| hook.call(config_path: config_path) }
  self.locale = config.robot.locale
  Robot.new.run
end
template_root() click to toggle source

The absolute path to Lita's templates directory. @return [String] The path. @since 3.0.0

# File lib/lita/common.rb, line 41
def template_root
  File.expand_path("../../../templates", __FILE__)
end