Skip to content

Commit

Permalink
Remove duplicate in Rails 2 & 3 initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Apr 8, 2010
1 parent 3e0fc41 commit c40c7f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
5 changes: 5 additions & 0 deletions init.rb
@@ -0,0 +1,5 @@
require 'delayed_job'

config.after_initialize do
Delayed::Worker.guess_backend
end
9 changes: 1 addition & 8 deletions lib/delayed/railtie.rb
Expand Up @@ -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
11 changes: 11 additions & 0 deletions lib/delayed/worker.rb
Expand Up @@ -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]
Expand Down
12 changes: 0 additions & 12 deletions rails/init.rb

This file was deleted.

0 comments on commit c40c7f9

Please sign in to comment.