Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove unused DiscoursePlugin class (#9715)

David Taylor5fc51ed49c86
diff --git a/config/application.rb b/config/application.rb
index 3eb998adca4..fab55ac9f4e 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -23,7 +23,6 @@ require 'sprockets/railtie'
# Plugin related stuff
require_relative '../lib/plugin_initialization_guard'
require_relative '../lib/discourse_event'
-require_relative '../lib/discourse_plugin'
require_relative '../lib/discourse_plugin_registry'
require_relative '../lib/plugin_gem'
diff --git a/lib/discourse_plugin.rb b/lib/discourse_plugin.rb
deleted file mode 100644
index 5d687e0788f..00000000000
--- a/lib/discourse_plugin.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-# A basic plugin for Discourse. Meant to be extended and filled in.
-# Most work is delegated to a registry.
-
-class DiscoursePlugin
-
- attr_reader :registry
-
- def initialize(registry)
- @registry = registry
- end
-
- def setup
- # Initialize the plugin here
- end
-
- # Loads and mixes in the plugin's mixins into the host app's classes.
- # A mixin named "UserMixin" will be included into the "User" class.
- def self.include_mixins
- mixins.each do |mixin|
- original_class = mixin.to_s.demodulize.sub("Mixin", "")
- dependency_file_name = original_class.underscore
- require_dependency(dependency_file_name)
- original_class.constantize.public_send(:include, mixin)
- end
- end
-
- # Find the modules defined in the plugin with "Mixin" in their name.
- def self.mixins
- constants.map { |const_name| const_get(const_name) }
- .select { |const| const.class == Module && const.name["Mixin"] }
- end
-
- def register_js(file, opts = {})
- @registry.register_js(file, opts)
- end
-
- def register_css(file, plugin_directory_name)
- @registry.register_css(file, plugin_directory_name)
- end
-
- def register_archetype(name, options = {})
- @registry.register_archetype(name, options)
- end
-
- def listen_for(event_name)
- return unless self.respond_to?(event_name)
- DiscourseEvent.on(event_name, &self.method(event_name))
- end
-
-end
diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb
index 8e9dde7d82a..2022c24ccfe 100644
--- a/lib/discourse_plugin_registry.rb
+++ b/lib/discourse_plugin_registry.rb
@@ -296,10 +296,4 @@ class DiscoursePluginRegistry
locales.clear
end
- def self.setup(plugin_class)
- registry = DiscoursePluginRegistry.new
- plugin = plugin_class.new(registry)
- plugin.setup
- end
-
end
diff --git a/spec/components/discourse_plugin_spec.rb b/spec/components/discourse_plugin_spec.rb
deleted file mode 100644
index 12a19d94c56..00000000000
--- a/spec/components/discourse_plugin_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails_helper'
-
-describe DiscoursePlugin do
-
- class TestPlugin < DiscoursePlugin
- module SomeModule
- end
-
- module TestMixin
- end
- end
-
- let(:registry) { mock }
- let(:plugin) { TestPlugin.new(registry) }
-
- describe ".mixins" do
- it "finds its mixins" do
- expect(TestPlugin.mixins).to eq([TestPlugin::TestMixin])
- end
- end
-
- it "delegates adding js to the registry" do
- registry.expects(:register_js).with('test.js', any_parameters)
- plugin.register_js('test.js')
- end
-
- it "delegates adding css to the registry" do
- registry.expects(:register_css).with('test.css', 'test')
- plugin.register_css('test.css', 'test')
- end
-
- it "delegates creating archetypes" do
- registry.expects(:register_archetype).with('banana', oh: 'no!')
- plugin.register_archetype('banana', oh: 'no!')
- end
-
- context 'registering for callbacks' do
- before do
- plugin.stubs(:hello)
- @proc = plugin.listen_for(:hello).first
- end
-
- after do
- DiscourseEvent.off(:hello, &@proc)
- end
-
- it "calls the method when it is triggered" do
- plugin.expects(:hello).with('there')
- DiscourseEvent.trigger(:hello, 'there')
- end
-
- end
-
-end