6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/attachment_saver.rb', line 6
def saves_attachment(options = {})
extend ClassMethods
include InstanceMethods
class_attribute :attachment_options
self.attachment_options = options
attachment_options[:datastore] ||= 'file_system'
require "datastores/#{attachment_options[:datastore].to_s.underscore}"
include DataStores.const_get(attachment_options[:datastore].to_s.classify)
before_validation :before_validate_attachment before_save :save_attachment after_save :tidy_attachment
after_save :close_open_file
after_destroy :delete_attachment
if attachment_options[:formats] && reflect_on_association(:formats).nil? attachment_options[:processor] ||= 'image_science'
attachment_options[:derived_class] ||= DerivedImage
has_many :formats, :as => :original, :class_name => attachment_options[:derived_class].to_s, :dependent => :destroy
after_save :save_updated_derived_children
end
if attachment_options[:processor]
unless Object.const_defined?(:Processors) && Processors.const_defined?(attachment_options[:processor].to_s.classify)
require "processors/#{attachment_options[:processor].to_s.underscore}"
end
include Processors.const_get(attachment_options[:processor].to_s.classify)
end
end
|