class Gitlab::FileResponse

Wrapper class of file response.

Constants

HEADER_CONTENT_DISPOSITION

Attributes

filename[R]

Public Class Methods

new(file) click to toggle source
# File lib/gitlab/file_response.rb, line 8
def initialize(file)
  @file = file
end

Public Instance Methods

empty?() click to toggle source

@return [bool] Always false

# File lib/gitlab/file_response.rb, line 13
def empty?
  false
end
inspect() click to toggle source

@return [String] Formatted string with the class name, object id and filename.

# File lib/gitlab/file_response.rb, line 24
def inspect
  "#<#{self.class}:#{object_id} {filename: #{filename.inspect}}>"
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/gitlab/file_response.rb, line 28
def method_missing(name, *args, &block)
  if @file.respond_to?(name)
    @file.send(name, *args, &block)
  else
    super
  end
end
parse_headers!(headers) click to toggle source

Parse filename from the 'Content Disposition' header.

# File lib/gitlab/file_response.rb, line 41
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) click to toggle source
Calls superclass method
# File lib/gitlab/file_response.rb, line 36
def respond_to_missing?(method_name, include_private = false)
  super || @file.respond_to?(method_name, include_private)
end
to_h()
Alias for: to_hash
to_hash() click to toggle source

@return [Hash] A hash consisting of filename and io object

# File lib/gitlab/file_response.rb, line 18
def to_hash
  { filename: @filename, data: @file }
end
Also aliased as: to_h