Sha256: 32c5986e4270b6085d3268ff87ff3ec027288742968d86515658ce0a6c72d1a1

Contents?: true

Size: 869 Bytes

Versions: 4

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

require "i18n"

require_relative "util"

module Lita
  # A mixin for setting and getting a plugin's namespace.
  # @since 4.0.0
  module Namespace
    # Gets (and optionally sets) the namespace for a plugin. The namespace is generated from the
    # class's name by default.
    # @param value [String] If provided, sets the namespace of the plugin to the value.
    # @return [String] The namespace.
    # @raise [RuntimeError] If the plugin is an anonymous class, does not define +self.name+, and
    #   has not set a namespace manually.
    def namespace(value = nil)
      @namespace = value.to_s if value

      string_name = defined?(@namespace) ? @namespace : name

      if string_name
        Util.underscore(string_name.split("::").last)
      else
        raise I18n.t("lita.plugin.name_required")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rita-5.0.0.alpha.4 lib/lita/namespace.rb
rita-5.0.0.alpha.3 lib/lita/namespace.rb
rita-5.0.0.alpha.2 lib/lita/namespace.rb
rita-5.0.0.alpha.1 lib/lita/namespace.rb