Module: Lita

Extended by:
Registry::Mixins
Defined in:
lib/lita.rb,
lib/lita/cli.rb,
lib/lita/room.rb,
lib/lita/user.rb,
lib/lita/util.rb,
lib/lita/robot.rb,
lib/lita/rspec.rb,
lib/lita/timer.rb,
lib/lita/common.rb,
lib/lita/config.rb,
lib/lita/daemon.rb,
lib/lita/errors.rb,
lib/lita/logger.rb,
lib/lita/source.rb,
lib/lita/adapter.rb,
lib/lita/handler.rb,
lib/lita/message.rb,
lib/lita/version.rb,
lib/lita/callback.rb,
lib/lita/rack_app.rb,
lib/lita/registry.rb,
lib/lita/response.rb,
lib/lita/template.rb,
lib/lita/namespace.rb,
lib/lita/http_route.rb,
lib/lita/configurable.rb,
lib/lita/adapters/test.rb,
lib/lita/authorization.rb,
lib/lita/handlers/help.rb,
lib/lita/handlers/info.rb,
lib/lita/handlers/room.rb,
lib/lita/http_callback.rb,
lib/lita/rspec/handler.rb,
lib/lita/adapters/shell.rb,
lib/lita/handler/common.rb,
lib/lita/handlers/users.rb,
lib/lita/plugin_builder.rb,
lib/lita/route_validator.rb,
lib/lita/template_resolver.rb,
lib/lita/handler/chat_router.rb,
lib/lita/handler/http_router.rb,
lib/lita/middleware_registry.rb,
lib/lita/handler/event_router.rb,
lib/lita/configuration_builder.rb,
lib/lita/default_configuration.rb,
lib/lita/handlers/authorization.rb,
lib/lita/configuration_validator.rb,
lib/lita/rspec/matchers/deprecated.rb,
lib/lita/handlers/deprecation_check.rb,
lib/lita/rspec/matchers/chat_route_matcher.rb,
lib/lita/rspec/matchers/http_route_matcher.rb,
lib/lita/rspec/matchers/event_route_matcher.rb

Overview

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

Defined Under Namespace

Modules: Adapters, Configurable, Handlers, Logger, Namespace, RSpec, Util Classes: Adapter, Authorization, CLI, Callback, Config, Configuration, ConfigurationBuilder, ConfigurationValidator, Daemon, DefaultConfiguration, Error, HTTPCallback, HTTPRoute, Handler, Message, MiddlewareRegistry, MissingTemplateError, MissingTemplateRootError, PluginBuilder, RackApp, RedisError, Registry, Response, Robot, Room, RouteValidator, Source, Template, TemplateResolver, Timer, User, ValidationError

Constant Summary collapse

REDIS_NAMESPACE =

The base Redis namespace for all Lita data.

"lita"
VERSION =

The current version of Lita.

"4.8.0"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Registry::Mixins

adapters, config, configure, handlers, hooks, register_adapter, register_handler, register_hook, reset, reset_adapters, reset_config, reset_handlers, reset_hooks

Class Attribute Details

.test_modeBoolean Also known as: test_mode?

A mode that makes minor changes to the Lita runtime to improve testability.

Returns:

  • (Boolean)

    Whether or not test mode is active.

Since:

  • 4.0.0


37
38
39
# File 'lib/lita.rb', line 37

def test_mode
  @test_mode
end

.version_3_compatibility_modeBoolean Also known as: version_3_compatibility_mode?

A special mode to ensure that tests written for Lita 3 plugins continue to work.

Returns:

  • (Boolean)

    Whether or not version 3 compatibility mode is active.

Since:

  • 4.0.0


31
32
33
# File 'lib/lita.rb', line 31

def version_3_compatibility_mode
  @version_3_compatibility_mode
end

Class Method Details

.default_locale=(new_locale) ⇒ void

This method returns an undefined value.

Sets I18n.default_locale, normalizing the provided locale name.

This is preferred over locale= as it affects all threads.

Parameters:

  • new_locale (Symbol, String)

    The code of the locale to use.

Since:

  • 4.8.0


34
35
36
# File 'lib/lita/common.rb', line 34

def default_locale=(new_locale)
  I18n.default_locale = new_locale.to_s.tr("_", "-")
end

.load_locales(paths) ⇒ void

This method returns an undefined value.

Adds one or more paths to the I18n load path and reloads I18n.

Parameters:

  • paths (String, Array<String>)

    The path(s) to add.

Since:

  • 3.0.0


10
11
12
13
# File 'lib/lita/common.rb', line 10

def load_locales(paths)
  I18n.load_path.concat(Array(paths))
  I18n.reload!
end

.locale=(new_locale) ⇒ void

This method returns an undefined value.

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 default_locale= which will affect all threads.

Parameters:

  • new_locale (Symbol, String)

    The code of the locale to use.

Since:

  • 3.0.0


24
25
26
# File 'lib/lita/common.rb', line 24

def locale=(new_locale)
  I18n.locale = new_locale.to_s.tr("_", "-")
end

.logger::Logger

The global Logger object.

Returns:

  • (::Logger)

    The global Logger object.


42
43
44
# File 'lib/lita.rb', line 42

def logger
  @logger ||= Logger.get_logger(config.robot.log_level, config.robot.log_formatter)
end

.redisRedis::Namespace

The root Redis object.

Returns:

  • (Redis::Namespace)

    The root Redis object.


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ void

This method returns an undefined value.

Loads user configuration and starts the robot.

Parameters:

  • config_path (String) (defaults to: nil)

    The path to the user configuration file.


73
74
75
76
77
78
79
80
81
# 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_rootString

The absolute path to Lita's templates directory.

Returns:

  • (String)

    The path.

Since:

  • 3.0.0


41
42
43
# File 'lib/lita/common.rb', line 41

def template_root
  File.expand_path("../../../templates", __FILE__)
end