From 499882d4d4d70c1df58d1c32e6e75c44fd98fec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 28 Mar 2014 21:36:38 -0300 Subject: [PATCH] Use ActiveSupport.on_load hooks to extend rails components Checking if the constant is define and including the extensions directly in the base class will for the class to be loaded. This may cause these components to be loaded before the time and be missconfigured if the sidekiq railtie is loaded before the components railtie. It is unlikely to happen but is better be safe. --- lib/sidekiq/rails.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sidekiq/rails.rb b/lib/sidekiq/rails.rb index a6f495e8..f261093a 100644 --- a/lib/sidekiq/rails.rb +++ b/lib/sidekiq/rails.rb @@ -1,11 +1,11 @@ module Sidekiq def self.hook_rails! - if defined?(::ActiveRecord) - ::ActiveRecord::Base.__send__(:include, Sidekiq::Extensions::ActiveRecord) + ActiveSupport.on_load(:active_record) do + include Sidekiq::Extensions::ActiveRecord end - if defined?(::ActionMailer) - ::ActionMailer::Base.extend(Sidekiq::Extensions::ActionMailer) + ActiveSupport.on_load(:action_mailer) do + extend Sidekiq::Extensions::ActionMailer end end