0
@@ -44,23 +44,28 @@ module Technoweenie # :nodoc:
0
options[:thumbnails] ||= {}
0
options[:thumbnail_class] ||= self
0
options[:s3_access] ||= :public_read
0
+ options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
0
+ # doing these shenanigans so that #attachment_options is available to processors and backends
0
+ class_inheritable_accessor :attachment_options
0
+ self.attachment_options = options
0
# only need to define these once on a class
0
- unless included_modules.include? InstanceMethods
0
- class_inheritable_accessor :attachment_options
0
+ unless included_modules.include?(InstanceMethods)
0
attr_accessor :thumbnail_resize_options
0
- options[:storage] ||= (options[:file_system_path] || options[:path_prefix]) ? :file_system : :db_file
0
- options[:path_prefix] ||= options[:file_system_path]
0
- if options[:path_prefix].nil?
0
- options[:path_prefix] = options[:storage] == :s3 ? table_name : File.join("public", table_name)
0
+ attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
0
+ attachment_options[:path_prefix] ||= attachment_options[:file_system_path]
0
+ if attachment_options[:path_prefix].nil?
0
+ attachment_options[:path_prefix] = attachment_options[:storage] == :s3 ? table_name : File.join("public", table_name)
0
-
options[:path_prefix] = options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
0
+
attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
0
with_options :foreign_key => 'parent_id' do |m|
0
- m.has_many :thumbnails, :
dependent => :destroy, :class_name => options[:thumbnail_class].to_s
0
+ m.has_many :thumbnails, :
class_name => attachment_options[:thumbnail_class].to_s
0
m.belongs_to :parent, :class_name => base_class.to_s
0
+ before_destroy :destroy_thumbnails
0
before_validation :set_size_from_temp_path
0
after_save :after_process_attachment
0
@@ -68,7 +73,7 @@ module Technoweenie # :nodoc:
0
include InstanceMethods
0
include Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
0
- case
options[:processor]
0
+ case
attachment_options[:processor]
0
processors = Technoweenie::AttachmentFu.default_processors.dup
0
@@ -79,13 +84,14 @@ module Technoweenie # :nodoc:
0
- include Technoweenie::AttachmentFu::Processors.const_get("#{options[:processor].to_s.classify}Processor")
0
+ include Technoweenie::AttachmentFu::Processors.const_get("#{options[:processor].to_s.classify}Processor")
0
+ rescue LoadError, MissingSourceFile
0
+ puts "Problems loading #{options[:processor]}Processor: #{$!}"
0
after_validation :process_attachment
0
- options[:content_type] = [options[:content_type]].flatten.collect { |t| t == :image ? Technoweenie::AttachmentFu.content_types : t }.flatten unless options[:content_type].nil?
0
- self.attachment_options = options
0
@@ -384,6 +390,11 @@ module Technoweenie # :nodoc:
0
+ # Removes the thumbnails for the attachment, if it has any
0
+ def destroy_thumbnails
0
+ self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
Comments
No one has commented yet.