Commit f1118c6b by Jon Yurek

Added Paperclip::Processor as a necessary superclass of Thumbnail (and all processors)

parent 5a731302
......@@ -29,9 +29,15 @@ require 'tempfile'
require 'paperclip/upfile'
require 'paperclip/iostream'
require 'paperclip/geometry'
require 'paperclip/processor'
require 'paperclip/thumbnail'
require 'paperclip/storage'
require 'paperclip/attachment'
if defined? 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.
......@@ -81,7 +87,9 @@ module Paperclip
def processor name
name = name.to_s.camelize
Paperclip.const_get(name) if Paperclip.const_defined?(name)
processor = Paperclip.const_get(name)
raise PaperclipError.new("Processor #{name} was not found") unless processor.ancestors.include?(Paperclip::Processor)
processor
end
end
......
module Paperclip
class Processor
attr_accessor :file, :options
def initialize file, options = {}
@file = file
@options = options
end
def make
end
def self.make file, options = {}
new(file, options).make
end
end
end
module Paperclip
# Handles thumbnailing images that are uploaded.
class Thumbnail
class Thumbnail < Processor
attr_accessor :file, :current_geometry, :target_geometry, :format, :whiny, :convert_options
attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
......@@ -11,6 +11,7 @@ module Paperclip
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
def initialize file, options = {}
super
geometry = options[:geometry]
@file = file
@crop = geometry[-1,1] == '#'
......@@ -24,12 +25,6 @@ module Paperclip
@basename = File.basename(@file.path, @current_format)
end
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# resulting Tempfile.
def self.make file, options = {}
new(file, options).make
end
# Returns true if the +target_geometry+ is meant to crop.
def crop?
@crop
......
......@@ -32,8 +32,12 @@ class PaperclipTest < Test::Unit::TestCase
end
end
should "return nil when sent #processor and the name of a class that doesn't exist" do
assert_nil Paperclip.processor(:boogey_man)
should "raise when sent #processor and the name of a class that exists but isn't a subclass of Processor" do
assert_raises(Paperclip::PaperclipError){ Paperclip.processor(:attachment) }
end
should "raise when sent #processor and the name of a class that doesn't exist" do
assert_raises(NameError){ Paperclip.processor(:boogey_man) }
end
should "return a class when sent #processor and the name of a class under Paperclip" do
......
require 'test/helper'
class ProcessorTest < Test::Unit::TestCase
should "instantiate and call #make when sent #make to the class" do
processor = mock
processor.expects(:make).with()
Paperclip::Processor.expects(:new).with(:one, :two).returns(processor)
Paperclip::Processor.make(:one, :two)
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