Class: Lita::TemplateResolver Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/template_resolver.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Finds the file path of the most appropriate template for the given adapter.

Since:

  • 4.2.0

Instance Method Summary collapse

Constructor Details

#initialize(template_root, template_name, adapter_name) ⇒ TemplateResolver

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TemplateResolver.

Parameters:

  • template_root (String)

    The directory to search for templates.

  • template_name (String)

    The name of the template to search for.

  • adapter_name (String, Symbol)

    The name of the current adapter.

Since:

  • 4.2.0


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

def initialize(template_root, template_name, adapter_name)
  @template_root = template_root
  @template_name = template_name
  @adapter_name = adapter_name
end

Instance Method Details

#resolveString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the adapter-specific template, falling back to a generic template.

Returns:

  • (String)

    The path of the template to use.

Raises:

Since:

  • 4.2.0


18
19
20
21
22
# File 'lib/lita/template_resolver.rb', line 18

def resolve
  return adapter_template if File.exist?(adapter_template)
  return generic_template if File.exist?(generic_template)
  raise MissingTemplateError, I18n.t("lita.template.missing_template", path: generic_template)
end