Module: Lita

Extended by:
Registry::Mixins
Defined in:
lib/lita.rb,
lib/lita/cli.rb,
lib/lita/util.rb,
lib/lita/user.rb,
lib/lita/robot.rb,
lib/lita/rspec.rb,
lib/lita/timer.rb,
lib/lita/daemon.rb,
lib/lita/errors.rb,
lib/lita/source.rb,
lib/lita/logger.rb,
lib/lita/common.rb,
lib/lita/config.rb,
lib/lita/version.rb,
lib/lita/handler.rb,
lib/lita/message.rb,
lib/lita/adapter.rb,
lib/lita/rack_app.rb,
lib/lita/response.rb,
lib/lita/registry.rb,
lib/lita/callback.rb,
lib/lita/namespace.rb,
lib/lita/http_route.rb,
lib/lita/configurable.rb,
lib/lita/rspec/handler.rb,
lib/lita/handlers/help.rb,
lib/lita/handlers/room.rb,
lib/lita/authorization.rb,
lib/lita/handlers/info.rb,
lib/lita/http_callback.rb,
lib/lita/plugin_builder.rb,
lib/lita/handlers/users.rb,
lib/lita/adapters/shell.rb,
lib/lita/handler/common.rb,
lib/lita/route_validator.rb,
lib/lita/handler/http_router.rb,
lib/lita/middleware_registry.rb,
lib/lita/handler/chat_router.rb,
lib/lita/handler/event_router.rb,
lib/lita/default_configuration.rb,
lib/lita/configuration_builder.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, PluginBuilder, RackApp, RedisError, Registry, Response, Robot, RouteValidator, Source, Timer, User, ValidationError

Constant Summary collapse

REDIS_NAMESPACE =

The base Redis namespace for all Lita data.

"lita"
VERSION =

The current version of Lita.

"4.0.4"

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.

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.

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

.load_locales(paths) ⇒ void

This method returns an undefined value.

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

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.

Since:

  • 3.0.0


19
20
21
# File 'lib/lita/common.rb', line 19

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

.logger::Logger

The global Logger object.


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

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

.redisRedis::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.


73
74
75
76
77
78
79
80
# 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
  self.locale = config.robot.locale
  Robot.new.run
end

.template_rootString

The absolute path to Lita's templates directory.

Since:

  • 3.0.0


26
27
28
# File 'lib/lita/common.rb', line 26

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