0
@@ -45,60 +45,57 @@ module Technoweenie # :nodoc:
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
unless options[:thumbnails].is_a?(Hash)
0
raise ArgumentError, ":thumbnails option should be a hash: e.g. :thumbnails => { :foo => '50x50' }"
0
+ extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods)
0
+ include InstanceMethods unless included_modules.include?(InstanceMethods)
0
+ parent_options = attachment_options || {}
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
- attr_accessor :thumbnail_resize_options
0
+ attr_accessor :thumbnail_resize_options
0
+ attachment_options[:storage] ||= (attachment_options[:file_system_path] || attachment_options[:path_prefix]) ? :file_system : :db_file
0
+ attachment_options[:storage] ||= parent_options[:storage]
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
+ 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, :class_name => attachment_options[:thumbnail_class].to_s
0
+ m.belongs_to :parent, :class_name => base_class.to_s
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
+ storage_mod = Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
0
+ include storage_mod unless included_modules.include?(storage_mod)
0
+ case attachment_options[:processor]
0
+ processors = Technoweenie::AttachmentFu.default_processors.dup
0
+ attachment_options[:processor] = "#{processors.first}Processor"
0
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get(attachment_options[:processor])
0
+ include processor_mod unless included_modules.include?(processor_mod)
0
+ rescue LoadError, MissingSourceFile
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, :class_name => attachment_options[:thumbnail_class].to_s
0
- m.belongs_to :parent, :class_name => base_class.to_s
0
- end unless options[:thumbnails].empty?
0
- before_destroy :destroy_thumbnails
0
- before_validation :set_size_from_temp_path
0
- after_save :after_process_attachment
0
- after_destroy :destroy_file
0
- include InstanceMethods
0
- include Technoweenie::AttachmentFu::Backends.const_get("#{options[:storage].to_s.classify}Backend")
0
- case attachment_options[:processor]
0
- processors = Technoweenie::AttachmentFu.default_processors.dup
0
- attachment_options[:processor] = "#{processors.first}Processor"
0
- include Technoweenie::AttachmentFu::Processors.const_get(attachment_options[:processor])
0
- rescue LoadError, MissingSourceFile
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
+ processor_mod = Technoweenie::AttachmentFu::Processors.const_get("#{attachment_options[:processor].to_s.classify}Processor")
0
+ include processor_mod unless included_modules.include?(processor_mod)
0
+ rescue LoadError, MissingSourceFile
0
+ puts "Problems loading #{options[:processor]}Processor: #{$!}"
0
- after_validation :process_attachment
0
+ end unless parent_options[:processor] # Don't let child override processor
0
@@ -116,11 +113,19 @@ module Technoweenie # :nodoc:
0
content_types.include?(content_type)
0
- if defined?(::ActiveSupport::Callbacks)
0
- def self.extended(base)
0
+ def self.extended(base)
0
+ base.class_inheritable_accessor :attachment_options
0
+ base.before_destroy :destroy_thumbnails
0
+ base.before_validation :set_size_from_temp_path
0
+ base.after_save :after_process_attachment
0
+ base.after_destroy :destroy_file
0
+ base.after_validation :process_attachment
0
+ if defined?(::ActiveSupport::Callbacks)
0
base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
0
+ unless defined?(::ActiveSupport::Callbacks)
0
# Callback after an image has been resized.
0
# class Foo < ActiveRecord::Base
0
@@ -284,7 +289,8 @@ module Technoweenie # :nodoc:
0
# Gets an array of the currently used temp paths. Defaults to a copy of #full_filename.
0
- @temp_paths ||= (new_record? || !File.exist?(full_filename)) ? [] : [copy_to_temp_file(full_filename)]
0
+ @temp_paths ||= (new_record? || !respond_to?(:full_filename) || !File.exist?(full_filename) ?
0
+ [] : [copy_to_temp_file(full_filename)])
0
# Adds a new temp_path to the array. This should take a string or a Tempfile. This class makes no
Comments
No one has commented yet.