Class: Grape::ServeFile::FileBody
- Inherits:
-
Object
- Object
- Grape::ServeFile::FileBody
- Defined in:
- lib/grape/serve_file/file_body.rb
Overview
Class helps send file through API
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each ⇒ Object
-
#initialize(path) ⇒ FileBody
constructor
A new instance of FileBody.
-
#to_path ⇒ String
Need for Rack::Sendfile middleware.
Constructor Details
#initialize(path) ⇒ FileBody
Returns a new instance of FileBody.
12 13 14 |
# File 'lib/grape/serve_file/file_body.rb', line 12 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/grape/serve_file/file_body.rb', line 9 def path @path end |
Instance Method Details
#==(other) ⇒ Object
31 32 33 |
# File 'lib/grape/serve_file/file_body.rb', line 31 def ==(other) path == other.path end |
#each ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/grape/serve_file/file_body.rb', line 23 def each File.open(path, 'rb') do |file| while (chunk = file.read(CHUNK_SIZE)) yield chunk end end end |
#to_path ⇒ String
Need for Rack::Sendfile middleware
19 20 21 |
# File 'lib/grape/serve_file/file_body.rb', line 19 def to_path path end |