Class: Brut::FrontEnd::Download
- Inherits:
-
Object
- Object
- Brut::FrontEnd::Download
- Defined in:
- lib/brut/front_end/download.rb
Overview
Represents a file the browser is going to download. This can be returned from a handler to initiate a download instead of rendering content.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The data to be sent in the download.
Instance Method Summary collapse
-
#headers ⇒ Object
Access the necessary HTTP headers to allow this file to be downloaded.
-
#initialize(filename:, data:, content_type:, timestamp: false) ⇒ Download
constructor
Create a download.
Constructor Details
#initialize(filename:, data:, content_type:, timestamp: false) ⇒ Download
Create a download
15 16 17 18 19 20 |
# File 'lib/brut/front_end/download.rb', line 15 def initialize(filename:,data:,content_type:,timestamp: false) @filename = filename @data = data @content_type = content_type @timestamp = end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the data to be sent in the download.
6 7 8 |
# File 'lib/brut/front_end/download.rb', line 6 def data @data end |
Instance Method Details
#headers ⇒ Object
Access the necessary HTTP headers to allow this file to be downloaded
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/brut/front_end/download.rb', line 23 def headers filename = if @timestamp Time.now.strftime("%Y-%m-%dT%H-%M-%S") + "-" + @filename else @filename end { "content-disposition" => "attachment; filename=\"#{filename}\"", "content-type" => @content_type, } end |