Sha256: 2f76bc1326a5212b25c8b672a33e3fb442dac6e98047c323e94201cf46cca111

Contents?: true

Size: 1 KB

Versions: 16

Compression:

Stored size: 1 KB

Contents

module Paperclip
  # The Upfile module is a convenience module for adding uploaded-file-type methods
  # to the +File+ class. Useful for testing.
  #   user.avatar = File.new("test/test_avatar.jpg")
  module Upfile

    # Infer the MIME-type of the file from the extension.
    def content_type
      type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
      case type
      when %r"jpe?g"                 then "image/jpeg"
      when %r"tiff?"                 then "image/tiff"
      when %r"png", "gif", "bmp"     then "image/#{type}"
      when "txt"                     then "text/plain"
      when %r"html?"                 then "text/html"
      when "csv", "xml", "css", "js" then "text/#{type}"
      else "application/x-#{type}"
      end
    end

    # Returns the file's normal name.
    def original_filename
      File.basename(self.path)
    end

    # Returns the size of the file.
    def size
      File.size(self)
    end
  end

end

class File #:nodoc:
  include Paperclip::Upfile
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
jcnetdev-paperclip-1.1 lib/paperclip/upfile.rb
jeremydurham-merb_paperclip-0.9.12 lib/paperclip/upfile.rb
jeremydurham-merb_paperclip-0.9.13 lib/paperclip/upfile.rb
kdmny-spree-0.0.1 vendor/plugins/paperclip/lib/paperclip/upfile.rb
peterpunk-merb_paperclip-0.9.3 lib/paperclip/upfile.rb
peterpunk-merb_paperclip-0.9.4 lib/paperclip/upfile.rb
rughetto-merb_paperclip-0.9.13 lib/paperclip/upfile.rb
spree-0.8.4 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.8.5 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.6.0 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.7.1 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.7.0 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.8.0 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.8.1 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.8.2 vendor/plugins/paperclip/lib/paperclip/upfile.rb
spree-0.8.3 vendor/plugins/paperclip/lib/paperclip/upfile.rb