Commit 4e4f427c by Zach Church Committed by Prem Sichanugrist

Fix issue where custom processors are not loaded in Rails 3

In Rails 3, Paperclip gem being loaded before the Rails object is properly configured and causing those processors not get require'd. This patch should fix that by lazy-loaded the processor.

Closes #206, #233, #247, #480, #494
parent a44bbd51
......@@ -41,11 +41,6 @@ require 'paperclip/storage'
require 'paperclip/callback_compatability'
require 'paperclip/railtie'
require 'cocaine'
if defined?(Rails.root) && Rails.root
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor
end
end
# The base module that gets included in ActiveRecord::Base. See the
# documentation for Paperclip::ClassMethods for more useful information.
......@@ -106,6 +101,7 @@ module Paperclip
def processor name #:nodoc:
name = name.to_s.camelize
load_processor(name) unless Paperclip.const_defined?(name)
processor = Paperclip.const_get(name)
unless processor.ancestors.include?(Paperclip::Processor)
raise PaperclipError.new("Processor #{name} was not found")
......@@ -113,6 +109,12 @@ module Paperclip
processor
end
def load_processor(name)
if defined?(Rails.root) && Rails.root
require File.expand_path(Rails.root.join("lib", "paperclip_processors", "#{name.underscore}.rb"))
end
end
def each_instance_with_attachment(klass, name)
class_for(klass).all.each do |instance|
yield(instance) if instance.send(:"#{name}?")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment