Module: Rack::App::InstanceMethods::Payload

Included in:
Rack::App::InstanceMethods
Defined in:
lib/rack/app/instance_methods/payload.rb

Instance Method Summary collapse

Instance Method Details

#payloadObject



3
4
5
# File 'lib/rack/app/instance_methods/payload.rb', line 3

def payload
  request.env[Rack::App::Constants::ENV::PAYLOAD_GETTER].call
end

#payload_streamObject



7
8
9
10
11
12
13
14
# File 'lib/rack/app/instance_methods/payload.rb', line 7

def payload_stream
  return nil unless @request.body.respond_to?(:gets)
  while chunk = @request.body.gets
    yield(chunk)
  end
  @request.body.rewind
  nil
end

#payload_to_file(file_path, file_mod = 'w') ⇒ Object



16
17
18
19
20
21
# File 'lib/rack/app/instance_methods/payload.rb', line 16

def payload_to_file(file_path, file_mod='w')
  return nil unless @request.body.respond_to?(:gets)
  File.open(file_path, file_mod) do |file|
    payload_stream{ |chunk| file.print(chunk) }
  end
end