Sha256: 6b98ba87ae566ad922c7ad0a02a6d9a789abce89aaba918ee177e8f36d4ad645

Contents?: true

Size: 982 Bytes

Versions: 23

Compression:

Stored size: 982 Bytes

Contents

module Lita
  # Constructs a Lita plugin from a block.
  # @since 4.0.0
  # @api private
  class PluginBuilder
    # @param namespace [String, Symbol] The Redis namespace to use for the plugin.
    # @yield The class body of the plugin.
    def initialize(namespace, &block)
      @namespace = namespace.to_s
      @block = block
    end

    # Constructs an {Lita::Adapter} from the provided block.
    # @return [Lita::Adapter]
    def build_adapter
      adapter = create_plugin(Adapter)
      adapter.class_exec(&@block)
      adapter
    end

    # Constructs a {Lita::Handler} from the provided block.
    # @return [Lita::Handler]
    def build_handler
      handler = create_plugin(Handler)
      handler.class_exec(&@block)
      handler
    end

    private

    # Creates a class of the relevant plugin type and sets its namespace.
    def create_plugin(plugin_type)
      plugin = Class.new(plugin_type)
      plugin.namespace(@namespace)
      plugin
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
lita-4.8.0 lib/lita/plugin_builder.rb
lita-4.8.0.beta1 lib/lita/plugin_builder.rb
lita-4.7.1 lib/lita/plugin_builder.rb
lita-4.7.0 lib/lita/plugin_builder.rb
lita-4.6.1 lib/lita/plugin_builder.rb
lita-4.6.0 lib/lita/plugin_builder.rb
lita-4.5.0 lib/lita/plugin_builder.rb
lita-4.4.3 lib/lita/plugin_builder.rb
lita-4.4.2 lib/lita/plugin_builder.rb
lita-4.4.1 lib/lita/plugin_builder.rb
lita-4.4.0 lib/lita/plugin_builder.rb
lita-4.3.2 lib/lita/plugin_builder.rb
lita-4.3.1 lib/lita/plugin_builder.rb
lita-4.3.0 lib/lita/plugin_builder.rb
lita-4.2.1 lib/lita/plugin_builder.rb
lita-4.2.0 lib/lita/plugin_builder.rb
lita-4.1.0 lib/lita/plugin_builder.rb
lita-4.0.4 lib/lita/plugin_builder.rb
lita-4.0.3 lib/lita/plugin_builder.rb
lita-4.0.2 lib/lita/plugin_builder.rb