Module: Lita::Handler::Common::ClassMethods

Defined in:
lib/lita/handler/common.rb

Overview

Common class-level methods for all handlers.

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#log_error(robot, error) ⇒ Object

Logs an error raised by a plugin.

Since:

  • 4.0.0


42
43
44
45
46
47
48
49
50
51
# 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) ⇒ String

Gets (and optionally sets) the directory where the handler's templates are stored.

Parameters:

  • path (String) (defaults to: nil)

    If provided, sets the template root to this value.

Returns:

  • (String)

    The template root path.

Raises:

Since:

  • 4.0.0


20
21
22
23
24
25
26
27
28
# 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 = {}) ⇒ String Also known as: t

Returns the translation for a key, automatically namespaced to the handler.

Parameters:

  • key (String)

    The key of the translation.

  • hash (Hash) (defaults to: {})

    An optional hash of values to be interpolated in the string.

Returns:

  • (String)

    The translated string.

Since:

  • 3.0.0


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

def translate(key, hash = {})
  I18n.translate("lita.handlers.#{namespace}.#{key}", hash)
end