Class: Shrine::Plugins::RackResponse::FileResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/rack_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileResponse

Returns a new instance of FileResponse.


21
22
23
# File 'lib/shrine/plugins/rack_response.rb', line 21

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.


19
20
21
# File 'lib/shrine/plugins/rack_response.rb', line 19

def file
  @file
end

Instance Method Details

#call(**options) ⇒ Object

Returns a Rack response triple for the uploaded file.


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shrine/plugins/rack_response.rb', line 26

def call(**options)
  file.open unless file.opened?

  options[:range] = parse_content_range(options[:range]) if options[:range]

  status  = rack_status(**options)
  headers = rack_headers(**options)
  body    = rack_body(**options)

  [status, headers, body]
end