Class: Shrine::Plugins::RackResponse::FileBody
- Inherits:
-
Object
- Object
- Shrine::Plugins::RackResponse::FileBody
- Defined in:
- lib/shrine/plugins/rack_response.rb
Overview
Implements the interface of a Rack response body object.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #bytesize ⇒ Object
-
#close ⇒ Object
Closes the file when response body is closed by the web server.
-
#each(&block) ⇒ Object
Streams the uploaded file directly from the storage.
-
#initialize(file, range: nil) ⇒ FileBody
constructor
A new instance of FileBody.
-
#method_missing(name, *args, &block) ⇒ Object
Rack::Sendfile is activated when response body responds to #to_path.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Rack::Sendfile is activated when response body responds to #to_path.
Constructor Details
#initialize(file, range: nil) ⇒ FileBody
Returns a new instance of FileBody.
127 128 129 130 |
# File 'lib/shrine/plugins/rack_response.rb', line 127 def initialize(file, range: nil) @file = file @range = range end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Rack::Sendfile is activated when response body responds to #to_path.
156 157 158 |
# File 'lib/shrine/plugins/rack_response.rb', line 156 def method_missing(name, *args, &block) name == :to_path && path or super end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
125 126 127 |
# File 'lib/shrine/plugins/rack_response.rb', line 125 def file @file end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
125 126 127 |
# File 'lib/shrine/plugins/rack_response.rb', line 125 def range @range end |
Instance Method Details
#bytesize ⇒ Object
146 147 148 |
# File 'lib/shrine/plugins/rack_response.rb', line 146 def bytesize each.inject(0) { |sum, chunk| sum += chunk.length } end |
#close ⇒ Object
Closes the file when response body is closed by the web server.
142 143 144 |
# File 'lib/shrine/plugins/rack_response.rb', line 142 def close file.close end |
#each(&block) ⇒ Object
Streams the uploaded file directly from the storage.
133 134 135 136 137 138 139 |
# File 'lib/shrine/plugins/rack_response.rb', line 133 def each(&block) if range read_partial_chunks(&block) else read_chunks(&block) end end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Rack::Sendfile is activated when response body responds to #to_path.
151 152 153 |
# File 'lib/shrine/plugins/rack_response.rb', line 151 def respond_to_missing?(name, include_private = false) name == :to_path && path end |