Class: HTTP::FormData::File
- Inherits:
-
Object
- Object
- HTTP::FormData::File
- Defined in:
- lib/http/form_data/file.rb
Overview
Represents file form param.
Constant Summary collapse
- DEFAULT_MIME =
Default MIME type
"application/octet-stream".freeze
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
Instance Method Summary collapse
-
#initialize(file_or_io, opts = {}) ⇒ File
constructor
A new instance of File.
-
#size ⇒ Fixnum
Returns content size.
-
#to_s ⇒ String
Returns content of a file of IO.
Constructor Details
#initialize(file_or_io, opts = {}) ⇒ File
Returns a new instance of File.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/http/form_data/file.rb', line 33 def initialize(file_or_io, opts = {}) @file_or_io = file_or_io opts = FormData.ensure_hash opts @mime_type = opts.fetch(:mime_type) { DEFAULT_MIME } @filename = opts.fetch :filename do case file_or_io when String then ::File.basename file_or_io when ::File then ::File.basename file_or_io.path else "stream-#{file_or_io.object_id}" end end end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
23 24 25 |
# File 'lib/http/form_data/file.rb', line 23 def filename @filename end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
23 24 25 |
# File 'lib/http/form_data/file.rb', line 23 def mime_type @mime_type end |
Instance Method Details
#size ⇒ Fixnum
Returns content size.
51 52 53 |
# File 'lib/http/form_data/file.rb', line 51 def size with_io(&:size) end |
#to_s ⇒ String
Returns content of a file of IO.
58 59 60 |
# File 'lib/http/form_data/file.rb', line 58 def to_s with_io(&:read) end |