Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making delayed_paperclip play nice with Railties, loading always afte…

…r paperclip.
  • Loading branch information...
commit 72ed85eee35e10ecb5cfacda617da7a8ecb05c06 1 parent 7ef561d
@Bertg Bertg authored
View
4 init.rb
@@ -0,0 +1,4 @@
+require File.join(File.dirname(__FILE__), "lib", "delayed_paperclip")
+require 'delayed_paperclip/railtie'
+
+DelayedPaperclip::Railtie.insert
View
15 lib/delayed_paperclip.rb
@@ -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
View
6 lib/delayed_paperclip/jobs.rb
@@ -0,0 +1,6 @@
+module DelayedPaperclip
+ module Jobs
+ autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
+ autoload :Resque, 'delayed_paperclip/jobs/resque'
+ end
+end
View
21 lib/delayed_paperclip/railtie.rb
@@ -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
3  rails/init.rb
@@ -1 +1,2 @@
-require 'delayed_paperclip'
+require 'delayed_paperclip/railtie'
+DelayedPaperclip::Railtie.insert
View
3  test/test_helper.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.