Skip to content

Commit

Permalink
remove the horrible alias_method_chain fu -- expect processors to sim…
Browse files Browse the repository at this point in the history
…ply define _process_attachment
  • Loading branch information
osheroff committed Mar 17, 2011
1 parent 54fde14 commit 90ca895
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
10 changes: 8 additions & 2 deletions lib/technoweenie/attachment_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,15 @@ def find_or_initialize_thumbnail(file_name_suffix)
thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
end

# Stub for a #process_attachment method in a processor
def has_attachment_processor?
self.respond_to?(:_process_attachment)
end

def process_attachment
@saved_attachment ||= save_attachment?
if @saved_attachment && has_attachment_processor?
self._process_attachment
end
true
end

Expand Down Expand Up @@ -642,7 +648,7 @@ def after_process_attachment
if @saved_attachment
set_size_from_temp_path

if respond_to?(:process_attachment_with_processing) && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
if has_attachment_processor? && thumbnailable? && !attachment_options[:thumbnails].blank? && parent_id.nil?
temp_file = temp_path || create_temp_file
attachment_options[:thumbnails].each { |suffix, size| create_or_update_thumbnail(temp_file, suffix, *size) }
end
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ module Processors
module CoreImageProcessor
def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
def with_image(file, &block)
block.call OSX::CIImage.from(file)
end
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing
def _process_attachment
with_image do |img|
self.width = img.extent.size.width if respond_to?(:width)
self.height = img.extent.size.height if respond_to?(:height)
Expand All @@ -40,17 +38,17 @@ def resize_image(img, size)
new_size = [img.extent.size.width, img.extent.size.height] / size.to_s
processor.resize(new_size[0], new_size[1])
end

processor.render do |result|
self.width = result.extent.size.width if respond_to?(:width)
self.height = result.extent.size.height if respond_to?(:height)

# Get a new temp_path for the image before saving
temp_paths.unshift Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
result.save self.temp_path, OSX::NSJPEGFileType
self.size = File.size(self.temp_path)
end
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Processors
module ImageScienceProcessor
def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
Expand All @@ -16,8 +15,8 @@ def with_image(file, &block)
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing && image?
def _process_attachment
return unless image?
with_image do |img|
self.width = img.width if respond_to?(:width)
self.height = img.height if respond_to?(:height)
Expand Down Expand Up @@ -58,4 +57,4 @@ def resize_image(img, size)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Processors
module MiniMagickProcessor
def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
Expand All @@ -25,8 +24,7 @@ def with_image(file, &block)
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing
def _process_attachment
with_image do |img|
resize_image_or_thumbnail! img
self.width = img[:width] if respond_to?(:width)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Processors
module RmagickProcessor
def self.included(base)
base.send :extend, ClassMethods
base.alias_method_chain :process_attachment, :processing
end

module ClassMethods
Expand All @@ -26,8 +25,7 @@ def with_image(file, &block)
end

protected
def process_attachment_with_processing
return unless process_attachment_without_processing
def _process_attachment
with_image do |img|
resize_image_or_thumbnail! img
self.width = img.columns if respond_to?(:width)
Expand Down

0 comments on commit 90ca895

Please sign in to comment.