about summary refs log tree commit diff
path: root/lib/paperclip/type_corrector.rb
blob: 0b0c10a56e9965658599c9d8c4b5dfa5077c1c0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

require 'mime/types/columnar'

module Paperclip
  class TypeCorrector < Paperclip::Processor
    def make
      target_extension = options[:format]
      extension        = File.extname(attachment.instance.file_file_name)

      return @file unless options[:style] == :original && target_extension && extension != target_extension

      attachment.instance.file_content_type = options[:content_type] || attachment.instance.file_content_type
      attachment.instance.file_file_name    = File.basename(attachment.instance.file_file_name, '.*') + '.' + target_extension

      @file
    end
  end
end