Class: Grape::ServeFile::FileBody

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/serve_file/file_body.rb

Overview

Class helps send file through API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileBody

Returns a new instance of FileBody.

Parameters:

  • path (String)


12
13
14
# File 'lib/grape/serve_file/file_body.rb', line 12

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (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

#eachObject



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_pathString

Need for Rack::Sendfile middleware

Returns:

  • (String)


19
20
21
# File 'lib/grape/serve_file/file_body.rb', line 19

def to_path
  path
end