Much of MessageBus::Rack::Middleware can be private

Much of MessageBus::Rack::Middleware can be private

From 26d218758f5104d8bcfc7de71c6ebc7096d791cc Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Tue, 27 Nov 2018 22:48:29 -0200
Subject: [PATCH] Much of MessageBus::Rack::Middleware can be private


diff --git a/lib/message_bus/rack/middleware.rb b/lib/message_bus/rack/middleware.rb
index ef06b21..70532dc 100644
--- a/lib/message_bus/rack/middleware.rb
+++ b/lib/message_bus/rack/middleware.rb
@@ -9,37 +9,23 @@ module MessageBus::Rack; end
 # delivers existing messages from the backlog and informs a
 # `MessageBus::ConnectionManager` of a connection which is remaining open.
 class MessageBus::Rack::Middleware
-  def start_listener
-    unless @started_listener
-
-      thin = defined?(Thin::Server) && ObjectSpace.each_object(Thin::Server).to_a.first
-      thin_running = thin && thin.running?
-
-      @subscription = @bus.subscribe do |msg|
-        run = proc do
-          begin
-            @connection_manager.notify_clients(msg) if @connection_manager
-          rescue
-            @bus.logger.warn "Failed to notify clients: #{$!} #{$!.backtrace}"
-          end
-        end
-
-        if thin_running
-          EM.next_tick(&run)
-        else
-          @bus.timer.queue(&run)
-        end
-
-        @started_listener = true
-      end
-    end
+  def self.backlog_to_json(backlog)
+    m = backlog.map do |msg|
+      {
+        global_id: msg.global_id,
+        message_id: msg.message_id,
+        channel: msg.channel,
+        data: msg.data
+      }
+    end.to_a
+    JSON.dump(m)
   end
 
   def initialize(app, config = {})
     @app = app
     @bus = config[:message_bus] || MessageBus
     @connection_manager = MessageBus::ConnectionManager.new(@bus)
-    self.start_listener
+    start_listener
   end
 
   def stop_listener
@@ -49,18 +35,6 @@ class MessageBus::Rack::Middleware
     end
   end
 
-  def self.backlog_to_json(backlog)
-    m = backlog.map do |msg|
-      {
-        global_id: msg.global_id,
-        message_id: msg.message_id,
-        channel: msg.channel,
-        data: msg.data
-      }
-    end.to_a
-    JSON.dump(m)
-  end
-
   def call(env)
     return @app.call(env) unless env['PATH_INFO'] =~ /^\/message-bus\//
 
@@ -192,6 +166,8 @@ class MessageBus::Rack::Middleware
     end
   end
 
+  private
+
   def close_db_connection!
     # IMPORTANT
     # ConnectionManagement in Rails puts a BodyProxy around stuff
@@ -214,4 +190,30 @@ class MessageBus::Rack::Middleware
       end
     }
   end
+
+  def start_listener
+    unless @started_listener
+
+      thin = defined?(Thin::Server) && ObjectSpace.each_object(Thin::Server).to_a.first
+      thin_running = thin && thin.running?
+
+      @subscription = @bus.subscribe do |msg|
+        run = proc do
+          begin
+            @connection_manager.notify_clients(msg) if @connection_manager
+          rescue
+            @bus.logger.warn "Failed to notify clients: #{$!} #{$!.backtrace}"
+          end
+        end
+
+        if thin_running
+          EM.next_tick(&run)
+        else
+          @bus.timer.queue(&run)
+        end
+
+        @started_listener = true
+      end
+    end
+  end
 end

GitHub