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.
10 11 12 |
# File 'lib/grape/serve_file/file_body.rb', line 10 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/grape/serve_file/file_body.rb', line 7 def path @path end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 |
# File 'lib/grape/serve_file/file_body.rb', line 29 def ==(other) path == other.path end |
#each ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/grape/serve_file/file_body.rb', line 21 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
17 18 19 |
# File 'lib/grape/serve_file/file_body.rb', line 17 def to_path path end |