Class: Redactor2Rails::Http::QqFile
- Inherits:
-
Tempfile
- Object
- Tempfile
- Redactor2Rails::Http::QqFile
- Defined in:
- lib/redactor2_rails/http.rb
Overview
Usage (paperclip example)
Instance Attribute Summary collapse
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
Instance Method Summary collapse
- #body ⇒ Object
- #content_type ⇒ Object
- #fetch ⇒ Object
-
#initialize(filename, request, tmpdir = Dir.tmpdir) ⇒ QqFile
constructor
A new instance of QqFile.
Constructor Details
#initialize(filename, request, tmpdir = Dir.tmpdir) ⇒ QqFile
Returns a new instance of QqFile.
43 44 45 46 47 48 49 |
# File 'lib/redactor2_rails/http.rb', line 43 def initialize(filename, request, tmpdir = Dir.tmpdir) @original_filename = filename @request = request super Digest::SHA1.hexdigest(filename), tmpdir fetch end |
Instance Attribute Details
#original_filename ⇒ Object (readonly)
Returns the value of attribute original_filename.
57 58 59 |
# File 'lib/redactor2_rails/http.rb', line 57 def original_filename @original_filename end |
Instance Method Details
#body ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/redactor2_rails/http.rb', line 64 def body if @request.raw_post.respond_to?(:force_encoding) @request.raw_post.force_encoding('UTF-8') else @request.raw_post end end |
#content_type ⇒ Object
59 60 61 62 |
# File 'lib/redactor2_rails/http.rb', line 59 def content_type types = MIME::Types.type_for(original_filename) types.empty? ? @request.content_type : types.first.to_s end |
#fetch ⇒ Object
51 52 53 54 55 |
# File 'lib/redactor2_rails/http.rb', line 51 def fetch write(body) rewind self end |