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)

10
11
12
# File 'lib/grape/serve_file/file_body.rb', line 10

def initialize(path)
  @path = path
end

Instance Attribute Details

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

#eachObject


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_pathString

Need for Rack::Sendfile middleware

Returns:

  • (String)

17
18
19
# File 'lib/grape/serve_file/file_body.rb', line 17

def to_path
  path
end