Commit 630c6341 by Mike Burns

Add a Paperclip.register_processor configuration.

parent 6ced9eb3
......@@ -92,7 +92,7 @@ module Paperclip
# This method can log the command being run when
# Paperclip.options[:log_command] is set to true (defaults to false). This
# will only log if logging in general is set to true as well.
def run cmd, *params
def run(cmd, *params)
if options[:image_magick_path]
Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
end
......@@ -100,11 +100,16 @@ module Paperclip
Cocaine::CommandLine.new(cmd, *params).run
end
def processor name #:nodoc:
def processor(name) #:nodoc:
@known_processors ||= {}
if @known_processors[name.to_s]
@known_processors[name.to_s]
else
name = name.to_s.camelize
load_processor(name) unless Paperclip.const_defined?(name)
processor = Paperclip.const_get(name)
processor
@known_processors[name.to_s] = processor
end
end
def load_processor(name)
......@@ -113,6 +118,23 @@ module Paperclip
end
end
def clear_processors!
@known_processors.try(:clear)
end
# You can add your own processor via the Paperclip configuration. Normally
# Paperclip will load all processors from the
# Rails.root/lib/paperclip_processors directory, but here you can add any
# existing class using this mechanism.
#
# Paperclip.configure do |c|
# c.register_processor :watermarker, WatermarkingProcessor.new
# end
def register_processor(name, processor)
@known_processors ||= {}
@known_processors[name.to_s] = processor
end
def each_instance_with_attachment(klass, name)
class_for(klass).all.each do |instance|
yield(instance) if instance.send(:"#{name}?")
......
......@@ -272,4 +272,26 @@ class PaperclipTest < Test::Unit::TestCase
end
end
context "configuring a custom processor" do
setup do
@freedom_processor = Class.new do
def make(file, options = {}, attachment = nil)
file
end
end.new
Paperclip.configure do |config|
config.register_processor(:freedom, @freedom_processor)
end
end
should "be able to find the custom processor" do
assert_equal @freedom_processor, Paperclip.processor(:freedom)
end
teardown do
Paperclip.clear_processors!
end
end
end
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