diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index d8129e715f0..37b4a4d2751 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -48,15 +48,11 @@ class Engine < ::Rails::Engine initializer 'spree.core.initialize_subscribers' do |app| app.reloader.to_prepare do Spree::Event.require_subscriber_files - Spree::Event.subscribers.each_key do |klass| - klass.constantize.subscribe! - end + Spree::Event.subscribe_subscribers! end app.reloader.before_class_unload do - Spree::Event.subscribers.each_key do |klass| - klass.constantize.unsubscribe! - end + Spree::Event.unsubscribe_subscribers! end end diff --git a/core/lib/spree/event.rb b/core/lib/spree/event.rb index 35a0f00be39..171eb6d7862 100644 --- a/core/lib/spree/event.rb +++ b/core/lib/spree/event.rb @@ -136,6 +136,14 @@ def subscribers Spree::Config.events.subscribers end + def subscribe_subscribers! + subscribers.each_key { |klass| klass.constantize.subscribe! } + end + + def unsubscribe_subscribers! + subscribers.each_key { |klass| klass.constantize.unsubscribe! } + end + private def normalize_name(name)