Sha256: 86d90e245771f596d7edcb40bb0832fe66c063d8f088d879613bd6057c92058a

Contents?: true

Size: 1.69 KB

Versions: 14

Compression:

Stored size: 1.69 KB

Contents

require 'carrierwave'

module CarrierWave

  class SanitizedFile

    def original_filename=(filename)
      @original_filename = filename
    end

    def content_type=(content_type)
      @content_type = content_type
    end

    # 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

    alias_method_chain :copy_to, :content_type

    # 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

  end

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
      end
    end

    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
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 lib/locomotive/carrierwave/patches.rb
locomotive_cms-1.0.0.beta lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta12 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta11 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta10 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta9 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta8 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta7 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta5 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/carrierwave/patches.rb
locomotive_cms-0.0.4 lib/locomotive/carrierwave/patches.rb