Class: Gitlab::FileResponse
- Inherits:
-
Object
- Object
- Gitlab::FileResponse
- 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
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#empty? ⇒ bool
Always false.
-
#initialize(file) ⇒ FileResponse
constructor
A new instance of FileResponse.
-
#inspect ⇒ String
Formatted string with the class name, object id and filename.
- #method_missing(name, *args, &block) ⇒ Object
-
#parse_headers!(headers) ⇒ Object
Parse filename from the ‘Content Disposition’ header.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#to_hash ⇒ Hash
(also: #to_h)
A hash consisting of filename and io object.
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
#filename ⇒ Object (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.
15 16 17 |
# File 'lib/gitlab/file_response.rb', line 15 def empty? false end |
#inspect ⇒ String
Returns 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
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_hash ⇒ Hash Also known as: to_h
Returns 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 |