From aae9aa42fe4e2e2f4ff5c1a034b5a285abbf08b2 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 2 Apr 2014 15:45:22 +0000 Subject: [PATCH] anti-spam-plugin-wrapper: ensure to load concrete wrappers --- plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb b/plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb index 8bf1602..44490ba 100644 --- a/plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb +++ b/plugins/anti_spam/lib/anti_spam_plugin/wrapper.rb @@ -1,10 +1,11 @@ class AntiSpamPlugin::Wrapper < SimpleDelegator include Rakismet::Model - @@wrappers = [AntiSpamPlugin::CommentWrapper, AntiSpamPlugin::SuggestArticleWrapper] + @@wrappers = [] + cattr_accessor :wrappers def self.wrap(object) - wrapper = @@wrappers.find { |wrapper| wrapper.wraps?(object) } + wrapper = wrappers.find { |wrapper| wrapper.wraps?(object) } wrapper ? wrapper.new(object) : object end @@ -12,9 +13,11 @@ class AntiSpamPlugin::Wrapper < SimpleDelegator false end -# FIXME You can't take for granted that the wrappers will be loaded and, therefore, -# included in the @@wrappers variable. -# def self.inherited(child) -# @@wrappers << child -# end + def self.inherited(child) + wrappers << child + end +end + +Dir.glob(File.join(AntiSpamPlugin.root_path, 'lib', 'anti_spam_plugin', '*_wrapper.rb')) do |file| + load(file) end -- libgit2 0.21.2