FIX: The ability to globally add a munger for post analysis

FIX: The ability to globally add a munger for post analysis

diff --git a/lib/discourse_akismet/posts_bouncer.rb b/lib/discourse_akismet/posts_bouncer.rb
index 3d33773..8ff5a3a 100644
--- a/lib/discourse_akismet/posts_bouncer.rb
+++ b/lib/discourse_akismet/posts_bouncer.rb
@@ -2,6 +2,9 @@
 
 module DiscourseAkismet
   class PostsBouncer < Bouncer
+
+    @@munger = nil
+
     def self.to_check
       PostCustomField.where(name: 'AKISMET_STATE', value: 'new')
         .where('posts.id IS NOT NULL')
@@ -54,12 +57,12 @@ module DiscourseAkismet
       post.upsert_custom_fields(values)
     end
 
-    def munge_args(&block)
-      @munger = block
+    def self.munge_args(&block)
+      @@munger = block
     end
 
-    def reset_munge
-      @munger = nil
+    def self.reset_munge
+      @@munger = nil
     end
 
     def args_for(post)
@@ -78,7 +81,7 @@ module DiscourseAkismet
         extra_args[:comment_author_email] = post.user.try(:email)
       end
 
-      @munger.call(extra_args) if @munger
+      @@munger.call(extra_args) if @@munger
       extra_args
     end
 
diff --git a/spec/lib/posts_bouncer_spec.rb b/spec/lib/posts_bouncer_spec.rb
index eaf252e..e03ae4c 100644
--- a/spec/lib/posts_bouncer_spec.rb
+++ b/spec/lib/posts_bouncer_spec.rb
@@ -40,11 +40,11 @@ describe DiscourseAkismet::PostsBouncer do
 
     context "custom munge" do
       after do
-        subject.reset_munge
+        described_class.reset_munge
       end
 
       before do
-        subject.munge_args do |args|
+        described_class.munge_args do |args|
           args[:comment_author] = "CUSTOM: #{args[:comment_author]}"
           args.delete(:user_agent)
         end
@@ -55,7 +55,7 @@ describe DiscourseAkismet::PostsBouncer do
         expect(result[:user_agent]).to be_blank
         expect(result[:comment_author]).to eq("CUSTOM: #{post.user.username}")
 
-        subject.reset_munge
+        described_class.reset_munge
         result = subject.args_for(post)
         expect(result[:user_agent]).to eq('Discourse Agent')
         expect(result[:comment_author]).to eq(post.user.username)

GitHub sha: 50096e11