module Lita::Handler::Common::ClassMethods
Common
class-level methods for all handlers.
Public Instance Methods
log_error(robot, error)
click to toggle source
Logs an error raised by a plugin.
# File lib/lita/handler/common.rb, line 42 def log_error(robot, error) robot.config.robot.error_handler.call(error) Lita.logger.error I18n.t( "lita.handler.exception", handler: name, message: error.message, backtrace: error.backtrace.join("\n") ) raise error if Lita.test_mode? end
template_root(path = nil)
click to toggle source
Gets (and optionally sets) the directory where the handler's templates are stored. @param path [String] If provided, sets the template root to this value. @return [String] The template root path. @raise [MissingTemplateRootError] If accessed without setting a value first.
# File lib/lita/handler/common.rb, line 20 def template_root(path = nil) @template_root = path if path if defined?(@template_root) return @template_root else raise MissingTemplateRootError end end
translate(key, hash = {})
click to toggle source
Returns the translation for a key, automatically namespaced to the handler. @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. @since 3.0.0
# File lib/lita/handler/common.rb, line 35 def translate(key, hash = {}) I18n.translate("lita.handlers.#{namespace}.#{key}", **hash) end
Also aliased as: t