Class: OnyxCord::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/onyxcord/internal/upload.rb

Overview

Small wrapper for file uploads while keeping raw File/Tempfile support.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_typeObject (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

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/onyxcord/internal/upload.rb', line 6

def filename
  @filename
end

#ioObject (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

#pathObject



26
27
28
# File 'lib/onyxcord/internal/upload.rb', line 26

def path
  @io.path if @io.respond_to?(:path)
end

#readObject



18
19
20
# File 'lib/onyxcord/internal/upload.rb', line 18

def read(...)
  @io.read(...)
end

#rewindObject



22
23
24
# File 'lib/onyxcord/internal/upload.rb', line 22

def rewind
  @io.rewind if @io.respond_to?(:rewind)
end