lib/paperclip.rb in paperclip-2.4.1 vs lib/paperclip.rb in paperclip-2.4.2
- old
+ new
@@ -95,11 +95,12 @@
# will only log if logging in general is set to true as well.
def run(cmd, *params)
if options[:image_magick_path]
Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
end
- Cocaine::CommandLine.path = options[:command_path] || options[:image_magick_path]
+ command_path = options[:command_path] || options[:image_magick_path]
+ Cocaine::CommandLine.path = ( Cocaine::CommandLine.path ? [Cocaine::CommandLine.path, command_path ].flatten : command_path )
Cocaine::CommandLine.new(cmd, *params).run
end
def processor(name) #:nodoc:
@known_processors ||= {}
@@ -182,10 +183,23 @@
raise NameError, "uninitialized constant #{class_name}"
else
raise e
end
end
+
+ def check_for_url_clash(name,url,klass)
+ @names_url ||= {}
+ default_url = url || Attachment.default_options[:url]
+ if @names_url[name] && @names_url[name][:url] == default_url && @names_url[name][:class] != klass
+ log("Duplicate URL for #{name} with #{default_url}. This will clash with attachment defined in #{@names_url[name][:class]} class")
+ end
+ @names_url[name] = {:url => default_url, :class => klass}
+ end
+
+ def reset_duplicate_clash_check!
+ @names_url = nil
+ end
end
class PaperclipError < StandardError #:nodoc:
end
@@ -275,10 +289,24 @@
# and pass an array to :convert_options instead.
# * +storage+: Chooses the storage backend where the files will be stored. The current
# choices are :filesystem and :s3. The default is :filesystem. Make sure you read the
# documentation for Paperclip::Storage::Filesystem and Paperclip::Storage::S3
# for backend-specific options.
+ #
+ # It's also possible for you to dynamicly define your interpolation string for :url,
+ # :default_url, and :path in your model by passing a method name as a symbol as a argument
+ # for your has_attached_file definition:
+ #
+ # class Person
+ # has_attached_file :avatar, :default_url => :default_url_by_gender
+ #
+ # private
+ #
+ # def default_url_by_gender
+ # "/assets/avatars/default_#{gender}.png"
+ # end
+ # end
def has_attached_file name, options = {}
include InstanceMethods
if attachment_definitions.nil?
if respond_to?(:class_attribute)
@@ -287,10 +315,11 @@
write_inheritable_attribute(:attachment_definitions, {})
end
end
attachment_definitions[name] = {:validations => []}.merge(options)
- Paperclip.classes_with_attachments << self
+ Paperclip.classes_with_attachments << self unless Paperclip.classes_with_attachments.include?(self)
+ Paperclip.check_for_url_clash(name,attachment_definitions[name][:url],self.name)
after_save :save_attached_files
before_destroy :prepare_for_destroy
after_destroy :destroy_attached_files