engine/lib/locomotive/carrierwave/patches.rb

61 lines
1.7 KiB
Ruby
Raw Normal View History

require 'carrierwave'
2010-05-11 21:38:52 +00:00
module CarrierWave
2010-05-11 21:38:52 +00:00
class SanitizedFile
2010-05-11 21:38:52 +00:00
def original_filename=(filename)
@original_filename = filename
end
2010-05-11 21:38:52 +00:00
def content_type=(content_type)
@content_type = content_type
end
2010-05-11 21:38:52 +00:00
# http://github.com/jnicklas/carrierwave/issuesearch?state=closed&q=content+type#issue/48
def copy_to_with_content_type(new_path, permissions=nil)
new_file = self.copy_to_without_content_type(new_path, permissions)
new_file.content_type = self.content_type
new_file
end
2010-05-11 21:38:52 +00:00
alias_method_chain :copy_to, :content_type
2010-05-11 21:38:52 +00:00
# FIXME (Did) CarrierWave speaks mime type now
def content_type
return @content_type if @content_type
if @file.respond_to?(:content_type) and @file.content_type
@file.content_type.chomp
else
File.mime_type?(@file) if @file.is_a?(String)
end
end
2010-05-11 21:38:52 +00:00
end
2010-05-11 21:38:52 +00:00
end
module CarrierWave
module Mongoid
def validates_integrity_of(*attrs)
options = attrs.last.is_a?(Hash) ? attrs.last : {}
validates_each(*attrs) do |record, attr, value|
if record.send("#{attr}_integrity_error")
message = options[:message] || I18n.t('carrierwave.errors.integrity', :default => 'is not an allowed type of file.')
record.errors.add attr, message
end
2010-05-11 21:38:52 +00:00
end
end
2010-05-12 00:16:39 +00:00
def validates_processing_of(*attrs)
options = attrs.last.is_a?(Hash) ? attrs.last : {}
validates_each(*attrs) do |record, attr, value|
if record.send("#{attr}_processing_error")
message = options[:message] || I18n.t('carrierwave.errors.processing', :default => 'failed to be processed.')
record.errors.add attr, message
end
2010-05-12 00:16:39 +00:00
end
end
2010-05-11 21:38:52 +00:00
end
end