Permalink
Browse files

Automatic initialization for Rails 2 and Rails 3

  • Loading branch information...
1 parent aa93dae commit b9d9fc449b12ba7c2a165c530fa80d787b3220b3 @jyurek jyurek committed May 20, 2010
Showing with 25 additions and 4 deletions.
  1. +2 −3 lib/paperclip.rb
  2. +20 −0 lib/paperclip/railtie.rb
  3. +1 −1 paperclip.gemspec
  4. +2 −0 rails/init.rb
View
@@ -37,6 +37,7 @@
require 'paperclip/style'
require 'paperclip/attachment'
require 'paperclip/callback_compatability'
+require 'paperclip/railtie'
if defined?(Rails.root) && Rails.root
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor
@@ -47,7 +48,7 @@
# documentation for Paperclip::ClassMethods for more useful information.
module Paperclip
- VERSION = "2.3.2"
+ VERSION = "2.3.2.beta1"
class << self
# Provides configurability to Paperclip. There are a number of options available, such as:
@@ -71,8 +72,6 @@ def options
end
def configure
- ActiveRecord::Base.send(:include, Paperclip)
- File.send(:include, Paperclip::Upfile)
yield(self) if block_given?
end
View
@@ -0,0 +1,20 @@
+require 'paperclip'
+
+module Paperclip
+ if defined? Rails::Railtie
+ require 'rails'
+ class Railtie < Rails::Railtie
+ config.after_initialize do
+ Paperclip::Railtie.insert
+ end
+ end
+ end
+
+ class Railtie
+ def self.insert
+ ActiveRecord::Base.send(:include, Paperclip)
+ File.send(:include, Paperclip::Upfile)
+ end
+ end
+end
+
View
@@ -1,7 +1,7 @@
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'paperclip'
-include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{generators,lib,tasks,test,shoulda_macros}/**/*"].map do |glob|
+include_files = ["README*", "LICENSE", "Rakefile", "init.rb", "{lib,tasks,test,rails,generators,shoulda_macros}/**/*"].map do |glob|
Dir[glob]
end.flatten
exclude_files = ["test/s3.yml", "test/debug.log", "test/paperclip.db", "test/doc", "test/doc/*", "test/pkg", "test/pkg/*", "test/tmp", "test/tmp/*"].map do |glob|
View
@@ -0,0 +1,2 @@
+require 'paperclip/railtie'
+Paperclip::Railtie.insert

0 comments on commit b9d9fc4

Please sign in to comment.