Permalink
Browse files

Making delayed_paperclip play nice with Railties, loading always afte…

…r paperclip.
  • Loading branch information...
1 parent 7ef561d commit 72ed85eee35e10ecb5cfacda617da7a8ecb05c06 @Bertg Bertg committed Nov 12, 2011
Showing with 36 additions and 16 deletions.
  1. +4 −0 init.rb
  2. +1 −14 lib/delayed_paperclip.rb
  3. +6 −0 lib/delayed_paperclip/jobs.rb
  4. +21 −0 lib/delayed_paperclip/railtie.rb
  5. +2 −1 rails/init.rb
  6. +2 −1 test/test_helper.rb
View
@@ -0,0 +1,4 @@
+require File.join(File.dirname(__FILE__), "lib", "delayed_paperclip")
+require 'delayed_paperclip/railtie'
+
+DelayedPaperclip::Railtie.insert
View
@@ -1,16 +1,7 @@
-require 'paperclip'
-
-require 'delayed_paperclip'
+require 'delayed_paperclip/jobs'
module DelayedPaperclip
- module Jobs
-
- autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
- autoload :Resque, 'delayed_paperclip/jobs/resque'
-
- end
-
class << self
def options
@@ -169,7 +160,3 @@ def post_process_styles_with_processing(*args)
end
end
-
-if Object.const_defined?("ActiveRecord")
- ActiveRecord::Base.send(:include, DelayedPaperclip)
-end
@@ -0,0 +1,6 @@
+module DelayedPaperclip
+ module Jobs
+ autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
+ autoload :Resque, 'delayed_paperclip/jobs/resque'
+ end
+end
@@ -0,0 +1,21 @@
+require 'delayed_paperclip'
+
+module DelayedPaperclip
+ if defined? Rails::Railtie
+ require 'rails'
+ class Railtie < Rails::Railtie
+ initializer 'delayed_paperclip.insert_into_active_record' do
+ ActiveSupport.on_load :paperclip do
+ DelayedPaperclip::Railtie.insert
+ end
+ end
+ end
+ end
+
+ class Railtie
+ def self.insert
+ ActiveRecord::Base.send(:include, DelayedPaperclip)
+ Paperclip::Attachment.send :include, DelayedPaperclip::Attachment
+ end
+ end
+end
View
@@ -1 +1,2 @@
-require 'delayed_paperclip'
+require 'delayed_paperclip/railtie'
+DelayedPaperclip::Railtie.insert
View
@@ -11,7 +11,8 @@
RAILS_ROOT = ROOT
$LOAD_PATH << File.join(ROOT, 'lib')
-require 'delayed_paperclip'
+require 'delayed_paperclip/railtie'
+DelayedPaperclip::Railtie.insert
class Test::Unit::TestCase
def setup

0 comments on commit 72ed85e

Please sign in to comment.