Permalink
Browse files

Dont load websocket server unless we are starting the rails server

  • Loading branch information...
1 parent dd7ab6c commit 8c033e447a2a59aa504fb3163378fc0d40a8bf5b @tye committed Nov 30, 2012
Showing with 27 additions and 22 deletions.
  1. +0 −22 config/initializers/websocket_server.rb
  2. +27 −0 lib/rubyception/engine.rb
View
22 config/initializers/websocket_server.rb
@@ -1,22 +0,0 @@
-require 'rubyception/websocket_server'
-require 'rubyception/subscriber'
-require 'rubyception/catcher'
-
-Rubyception::WebsocketServer.sockets = []
-Rubyception::WebsocketServer.new
-
-attach_to = [
- :action_controller,
- :action_view,
- :active_record,
- :action_mailer
-]
-attach_to.each do |notification|
- Rubyception::Subscriber.attach_to notification
-end
-
-if defined? ::ActionDispatch::DebugExceptions
- ::ActionDispatch::DebugExceptions.send(:include,Rubyception::ExceptionsCatcher)
-else
- ::ActionDispatch::ShowExceptions.send(:include,Rubyception::ExceptionsCatcher)
-end
View
27 lib/rubyception/engine.rb
@@ -1,5 +1,32 @@
module Rubyception
class Engine < ::Rails::Engine
isolate_namespace Rubyception
+ initializer 'rubyception.start_websocket', :after=> :build_middleware_stack do |app|
+ require 'rubyception/websocket_server'
+ require 'rubyception/subscriber'
+ require 'rubyception/catcher'
+
+ Rubyception::WebsocketServer.sockets = []
+ puts "[RUBYCEPTION] Starting Websocket server"
+ Rubyception::WebsocketServer.new
+
+ attach_to = [
+ :action_controller,
+ :action_view,
+ :active_record,
+ :action_mailer
+ ]
+ puts "[RUBYCEPTION] Adding notification subscribers"
+ attach_to.each do |notification|
+ Rubyception::Subscriber.attach_to notification
+ end
+
+ puts "[RUBYCEPTION] Adding exception catcher"
+ if defined? ::ActionDispatch::DebugExceptions
+ ::ActionDispatch::DebugExceptions.send(:include,Rubyception::ExceptionsCatcher)
+ else
+ ::ActionDispatch::ShowExceptions.send(:include,Rubyception::ExceptionsCatcher)
+ end
+ end
end
end

0 comments on commit 8c033e4

Please sign in to comment.