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'.freeze
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.
8 9 10 |
# File 'lib/gitlab/file_response.rb', line 8 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
28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/gitlab/file_response.rb', line 6 def filename @filename end |
Instance Method Details
#empty? ⇒ bool
Returns Always false.
13 14 15 |
# File 'lib/gitlab/file_response.rb', line 13 def empty? false end |
#inspect ⇒ String
Returns Formatted string with the class name, object id and filename.
24 25 26 |
# File 'lib/gitlab/file_response.rb', line 24 def inspect "#<#{self.class}:#{object_id} {filename: #{filename.inspect}}>" end |
#parse_headers!(headers) ⇒ Object
Parse filename from the ‘Content Disposition’ header.
41 42 43 44 |
# 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) ⇒ Boolean
36 37 38 |
# 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_hash ⇒ Hash Also known as: to_h
Returns A hash consisting of filename and io object.
18 19 20 |
# File 'lib/gitlab/file_response.rb', line 18 def to_hash { filename: @filename, data: @file } end |