Module: AttachmentFu::ActMethods
- Defined in:
- lib/attachment_fu.rb
Instance Method Summary collapse
-
#has_attachment(options = {}) ⇒ Object
-
:keep_profile
By default image EXIF data will be stripped to minimize image size.
-
Instance Method Details
#has_attachment(options = {}) ⇒ Object
-
:keep_profile
By default image EXIF data will be stripped to minimize image size. For small thumbnails this proivides important savings. Picture quality is not affected. Set to false if you want to keep the image profile as is. ImageScience will allways keep EXIF data.
Examples:
:max_size => 1.kilobyte
:size => 1.megabyte..2.megabytes
:content_type => 'application/pdf'
:content_type => ['application/pdf', 'application/msword', 'text/plain']
:content_type => :image, :resize_to => [50,50]
:content_type => ['application/pdf', :image], :resize_to => 'x50'
:thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
:storage => :file_system, :path_prefix => 'public/files'
:storage => :file_system, :path_prefix => 'public/files',
:content_type => :image, :resize_to => [50,50]
:storage => :file_system, :path_prefix => 'public/files',
:thumbnails => { :thumb => [50, 50], :geometry => 'x50' }
:storage => :s3
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/attachment_fu.rb', line 87 def ( = {}) # this allows you to redefine the acts' options for each subclass, however [:min_size] ||= 1 [:max_size] ||= 1.megabyte [:size] ||= ([:min_size]..[:max_size]) [:thumbnails] ||= {} [:thumbnail_class] ||= self [:s3_access] ||= :public_read [:cloudfront] ||= false [:content_type] = [[:content_type]].flatten.collect! { |t| t == :image ? AttachmentFu.content_types : t }.flatten unless [:content_type].nil? unless [:thumbnails].is_a?(Hash) raise ArgumentError, ":thumbnails option should be a hash: e.g. :thumbnails => { :foo => '50x50' }" end extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods) include InstanceMethods unless included_modules.include?(InstanceMethods) = || {} # doing these shenanigans so that #attachment_options is available to processors and backends self. = attr_accessor :thumbnail_resize_options [:storage] ||= ([:file_system_path] || [:path_prefix]) ? :file_system : :db_file [:storage] ||= [:storage] [:path_prefix] ||= [:file_system_path] if [:path_prefix].nil? [:path_prefix] = case [:storage] when :s3 then table_name when :cloud_files then table_name else File.join("public", table_name) end end [:path_prefix] = [:path_prefix][1..-1] if [:path_prefix].first == '/' = { :foreign_key => 'parent_id' } if [:association_options] .merge!([:association_options]) end () do |m| m.has_many :thumbnails, :class_name => "::#{[:thumbnail_class]}" m.belongs_to :parent, :class_name => "::#{base_class}" unless [:thumbnails].empty? end storage_mod = AttachmentFu::Backends.const_get("#{[:storage].to_s.classify}Backend") include storage_mod unless included_modules.include?(storage_mod) case [:processor] when :none, nil processors = AttachmentFu.default_processors.dup begin if processors.any? [:processor] = processors.first processor_mod = AttachmentFu::Processors.const_get("#{[:processor].to_s.classify}Processor") include processor_mod unless included_modules.include?(processor_mod) end rescue Object, Exception raise unless ($!) processors.shift retry end else begin processor_mod = AttachmentFu::Processors.const_get("#{[:processor].to_s.classify}Processor") include processor_mod unless included_modules.include?(processor_mod) rescue Object, Exception raise unless ($!) puts "Problems loading #{[:processor]}Processor: #{$!}" end end unless [:processor] # Don't let child override processor end |