Class: OnyxCord::Upload
- Inherits:
-
Object
- Object
- OnyxCord::Upload
- Defined in:
- lib/onyxcord/internal/upload.rb
Overview
Small wrapper for file uploads while keeping raw File/Tempfile support.
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io, filename: nil, content_type: nil) ⇒ Upload
constructor
A new instance of Upload.
- #path ⇒ Object
- #read ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(io, filename: nil, content_type: nil) ⇒ Upload
Returns a new instance of Upload.
12 13 14 15 16 |
# File 'lib/onyxcord/internal/upload.rb', line 12 def initialize(io, filename: nil, content_type: nil) @io = io @filename = filename || upload_filename(io) @content_type = content_type end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/onyxcord/internal/upload.rb', line 6 def content_type @content_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/onyxcord/internal/upload.rb', line 6 def filename @filename end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
6 7 8 |
# File 'lib/onyxcord/internal/upload.rb', line 6 def io @io end |
Class Method Details
.wrap(file) ⇒ Object
8 9 10 |
# File 'lib/onyxcord/internal/upload.rb', line 8 def self.wrap(file) file.is_a?(self) ? file : new(file) end |
Instance Method Details
#path ⇒ Object
26 27 28 |
# File 'lib/onyxcord/internal/upload.rb', line 26 def path @io.path if @io.respond_to?(:path) end |
#read ⇒ Object
18 19 20 |
# File 'lib/onyxcord/internal/upload.rb', line 18 def read(...) @io.read(...) end |
#rewind ⇒ Object
22 23 24 |
# File 'lib/onyxcord/internal/upload.rb', line 22 def rewind @io.rewind if @io.respond_to?(:rewind) end |