class Shrine::Plugins::RackResponse::FileBody

  1. lib/shrine/plugins/rack_response.rb
Superclass: Object

Implements the interface of a Rack response body object.

Methods

Public Class

  1. new

Public Instance

  1. bytesize
  2. close
  3. each
  4. file
  5. method_missing
  6. range
  7. respond_to_missing?

Attributes

file [R]
range [R]

Public Class methods

new(file, range: nil)
[show source]
    # File lib/shrine/plugins/rack_response.rb
127 def initialize(file, range: nil)
128   @file  = file
129   @range = range
130 end

Public Instance methods

bytesize()
[show source]
    # File lib/shrine/plugins/rack_response.rb
146 def bytesize
147   each.inject(0) { |sum, chunk| sum += chunk.length }
148 end
close()

Closes the file when response body is closed by the web server.

[show source]
    # File lib/shrine/plugins/rack_response.rb
142 def close
143   file.close
144 end
each(&block)

Streams the uploaded file directly from the storage.

[show source]
    # File lib/shrine/plugins/rack_response.rb
133 def each(&block)
134   if range
135     read_partial_chunks(&block)
136   else
137     read_chunks(&block)
138   end
139 end
method_missing(name, *args, &block)

Rack::Sendfile is activated when response body responds to to_path.

[show source]
    # File lib/shrine/plugins/rack_response.rb
156 def method_missing(name, *args, &block)
157   name == :to_path && path or super
158 end
respond_to_missing?(name, include_private = false)

Rack::Sendfile is activated when response body responds to to_path.

[show source]
    # File lib/shrine/plugins/rack_response.rb
151 def respond_to_missing?(name, include_private = false)
152   name == :to_path && path
153 end