Class: Shrine::DownloadEndpoint

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options) ⇒ DownloadEndpoint

Writes given options to instance variables.



101
102
103
104
105
# File 'lib/shrine/plugins/download_endpoint.rb', line 101

def initialize(options)
  options.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

Instance Method Details

#call(env) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/shrine/plugins/download_endpoint.rb', line 107

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["Content-Length"] ||= body.map(&:bytesize).inject(0, :+).to_s

  [status, headers, body]
end

#inspectObject Also known as: to_s



121
122
123
# File 'lib/shrine/plugins/download_endpoint.rb', line 121

def inspect
  "#<#{@shrine_class}::DownloadEndpoint>"
end