Class: Shrine::DownloadEndpoint
- Inherits:
-
Object
- Object
- Shrine::DownloadEndpoint
- Defined in:
- lib/shrine/plugins/download_endpoint.rb
Overview
Routes incoming requests. It first asserts that the storage is existent and allowed. Afterwards it proceeds with the file download using streaming.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options) ⇒ DownloadEndpoint
constructor
Writes given options to instance variables.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(options) ⇒ DownloadEndpoint
Writes given options to instance variables.
134 135 136 137 138 |
# File 'lib/shrine/plugins/download_endpoint.rb', line 134 def initialize() .each do |name, value| instance_variable_set("@#{name}", value) end end |
Instance Method Details
#call(env) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/shrine/plugins/download_endpoint.rb', line 140 def call(env) request = Rack::Request.new(env) status, headers, body = catch(:halt) do error!(405, "Method Not Allowed") unless request.get? handle_request(request) end headers = Rack::Headers[headers] if Rack.release >= "3" headers["Content-Length"] ||= body.respond_to?(:bytesize) ? body.bytesize.to_s : body.map(&:bytesize).inject(0, :+).to_s [status, headers, body] end |
#inspect ⇒ Object Also known as: to_s
156 157 158 |
# File 'lib/shrine/plugins/download_endpoint.rb', line 156 def inspect "#<#{@shrine_class}::DownloadEndpoint>" end |