class Lita::Adapter
Adapters are the glue between Lita's API and a chat service.
Constants
- REQUIRED_METHODS
The names of methods that should be implemented by an adapter. @since 4.4.0
Attributes
The instance of {Lita::Robot}. @return [Lita::Robot]
Public Class Methods
@param robot [Lita::Robot] The currently running robot.
# File lib/lita/adapter.rb, line 57 def initialize(robot) @robot = robot ensure_required_configs end
Defines configuration keys that are requried for the adapter to boot. @param keys [String, Symbol] The required keys. @return [void] @deprecated Will be removed in Lita 5.0. Use {Lita::Adapter#config} instead.
# File lib/lita/adapter.rb, line 38 def require_config(*keys) @required_configs ||= [] @required_configs.concat(keys.flatten.map(&:to_sym)) end
@!attribute [r] ::required_configs A list of configuration keys that are required for the adapter to boot. @return [Array] @deprecated Will be removed in Lita 5.0. Use {Lita::Adapter#configuration_builder} instead.
# File lib/lita/adapter.rb, line 29 def required_configs Lita.logger.warn(I18n.t("lita.adapter.required_configs_deprecated")) @required_configs end
Returns the translation for a key, automatically namespaced to the adapter. @param key [String] The key of the translation. @param hash [Hash] An optional hash of values to be interpolated in the string. @return [String] The translated string.
# File lib/lita/adapter.rb, line 49 def translate(key, hash = {}) I18n.translate("lita.adapters.#{namespace}.#{key}", hash) end
Public Instance Methods
The adapter's configuration object. @return [Lita::Configuration] The adapter's configuration object. @since 4.0.0
# File lib/lita/adapter.rb, line 65 def config robot.config.adapters.public_send(self.class.namespace) end
Formats a name for “mentioning” a user in a group chat. Override this method in child classes to customize the mention format for the chat service. @param name [String] The name to format as a mention name. @return [String] The formatted mention name. @since 3.1.0
# File lib/lita/adapter.rb, line 140 def mention_format(name) "#{name}:" end
@see .translate
# File lib/lita/adapter.rb, line 145 def translate(*args) self.class.translate(*args) end
Private Instance Methods
Returns the object used as the adapter's configuration.
# File lib/lita/adapter.rb, line 154 def adapter_config if Lita.version_3_compatibility_mode? Lita.config.adapter else robot.config.adapter end end
Logs a fatal message and aborts if a required config key is not set.
# File lib/lita/adapter.rb, line 163 def ensure_required_configs return if required_configs.nil? Lita.logger.warn(I18n.t("lita.adapter.require_config_deprecated")) missing_keys = missing_config_keys unless missing_keys.empty? Lita.logger.fatal(I18n.t("lita.adapter.missing_configs", configs: missing_keys.join(", "))) abort end end
Finds all missing config keys.
# File lib/lita/adapter.rb, line 177 def missing_config_keys required_configs.select do |key| key unless adapter_config[key] end end
Access the required configs without triggering the deprecation warning.
# File lib/lita/adapter.rb, line 184 def required_configs self.class.instance_variable_get(:@required_configs) end