Class: Buble::FileUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/buble/files.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io:, filename:, content_type: 'application/octet-stream', close_after: false) ⇒ FileUpload

Returns a new instance of FileUpload.



7
8
9
10
11
12
# File 'lib/buble/files.rb', line 7

def initialize(io:, filename:, content_type: 'application/octet-stream', close_after: false)
  @io = io
  @filename = filename
  @content_type = content_type
  @close_after = close_after
end

Instance Attribute Details

#close_afterObject (readonly)

Returns the value of attribute close_after.



5
6
7
# File 'lib/buble/files.rb', line 5

def close_after
  @close_after
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



5
6
7
# File 'lib/buble/files.rb', line 5

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/buble/files.rb', line 5

def filename
  @filename
end

#ioObject (readonly)

Returns the value of attribute io.



5
6
7
# File 'lib/buble/files.rb', line 5

def io
  @io
end

Class Method Details

.from_io(io, filename:, content_type: 'application/octet-stream') ⇒ Object



23
24
25
# File 'lib/buble/files.rb', line 23

def self.from_io(io, filename:, content_type: 'application/octet-stream')
  new(io: io, filename: filename, content_type: content_type, close_after: false)
end

.from_path(path, content_type: 'application/octet-stream') ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/buble/files.rb', line 14

def self.from_path(path, content_type: 'application/octet-stream')
  new(
    io: File.open(path, 'rb'),
    filename: File.basename(path),
    content_type: content_type,
    close_after: true
  )
end

Instance Method Details

#to_http_partObject



27
28
29
# File 'lib/buble/files.rb', line 27

def to_http_part
  HTTP::FilePart.new(io: io, filename: filename, content_type: content_type, close_after: close_after)
end