Permalink
Browse files

Remove duplicate in Rails 2 & 3 initializers

  • Loading branch information...
1 parent 3e0fc41 commit c40c7f9e1a6039a061a46ab5b32792b1055e5b9a @bkeepers bkeepers committed Apr 8, 2010
Showing with 17 additions and 20 deletions.
  1. +5 −0 init.rb
  2. +1 −8 lib/delayed/railtie.rb
  3. +11 −0 lib/delayed/worker.rb
  4. +0 −12 rails/init.rb
View
@@ -0,0 +1,5 @@
+require 'delayed_job'
+
+config.after_initialize do
+ Delayed::Worker.guess_backend
+end
View
@@ -4,14 +4,7 @@
module Delayed
class Railtie < Rails::Railtie
initializer :after_initialize do
- Delayed::Worker.backend ||= if defined?(ActiveRecord)
- :active_record
- elsif defined?(MongoMapper)
- :mongo_mapper
- else
- Delayed::Worker.logger.warn "Could not decide on a backend, defaulting to active_record"
- :active_record
- end
+ Delayed::Worker.guess_backend
end
end
end
View
@@ -32,6 +32,17 @@ def self.backend=(backend)
@@backend = backend
silence_warnings { ::Delayed.const_set(:Job, backend) }
end
+
+ def self.guess_backend
+ self.backend ||= if defined?(ActiveRecord)
+ :active_record
+ elsif defined?(MongoMapper)
+ :mongo_mapper
+ else
+ logger.warn "Could not decide on a backend, defaulting to active_record"
+ :active_record
+ end
+ end
def initialize(options={})
@quiet = options[:quiet]
View
@@ -1,12 +0,0 @@
-require 'delayed_job'
-
-config.after_initialize do
- Delayed::Worker.backend ||= if defined?(ActiveRecord)
- :active_record
- elsif defined?(MongoMapper)
- :mongo_mapper
- else
- Delayed::Worker.logger.warn "Could not decide on a backend, defaulting to active_record"
- :active_record
- end
-end

0 comments on commit c40c7f9

Please sign in to comment.