Class: Gitlab::FileResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/file_response.rb

Overview

Wrapper class of file response.

Constant Summary collapse

HEADER_CONTENT_DISPOSITION =
'Content-Disposition' 

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileResponse

Returns a new instance of FileResponse.

 10 11 12
# File 'lib/gitlab/file_response.rb', line 10 def initialize(file) @file = file end 

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

 30 31 32 33 34 35 36
# File 'lib/gitlab/file_response.rb', line 30 def method_missing(name, *args, &block) if @file.respond_to?(name) @file.send(name, *args, &block) else super end end 

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.

 8 9 10
# File 'lib/gitlab/file_response.rb', line 8 def filename @filename end 

Instance Method Details

#empty?bool

Returns Always false.

Returns:

  • (bool)

    Always false

 15 16 17
# File 'lib/gitlab/file_response.rb', line 15 def empty? false end 

#inspectString

Returns Formatted string with the class name, object id and filename.

Returns:

  • (String)

    Formatted string with the class name, object id and filename.

 26 27 28
# File 'lib/gitlab/file_response.rb', line 26 def inspect "#<#{self.class}:#{object_id} {filename: #{filename.inspect}}>" end 

#parse_headers!(headers) ⇒ Object

Parse filename from the ‘Content Disposition’ header.

 43 44 45 46
# File 'lib/gitlab/file_response.rb', line 43 def parse_headers!(headers) @filename = headers[HEADER_CONTENT_DISPOSITION].split('filename=')[1] @filename = @filename[1...-1] if @filename[0] == '"' # Unquote filenames end 

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)
 38 39 40
# File 'lib/gitlab/file_response.rb', line 38 def respond_to_missing?(method_name, include_private = false) super || @file.respond_to?(method_name, include_private) end 

#to_hashHash Also known as: to_h

Returns A hash consisting of filename and io object.

Returns:

  • (Hash)

    A hash consisting of filename and io object

 20 21 22
# File 'lib/gitlab/file_response.rb', line 20 def to_hash { filename: @filename, data: @file } end