Class: Esplanade::Request::Raw::Body
- Inherits:
-
Object
- Object
- Esplanade::Request::Raw::Body
- Defined in:
- lib/esplanade/request/raw/body.rb
Instance Method Summary collapse
-
#initialize(raw_request, env) ⇒ Body
constructor
A new instance of Body.
- #reduced_version ⇒ Object
- #to_hash ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(raw_request, env) ⇒ Body
Returns a new instance of Body.
5 6 7 8 |
# File 'lib/esplanade/request/raw/body.rb', line 5 def initialize(raw_request, env) @raw_request = raw_request @env = env end |
Instance Method Details
#reduced_version ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/esplanade/request/raw/body.rb', line 24 def reduced_version @reduced_version ||= if to_string && to_string.size >= 1000 "#{to_string[0..499]}...#{to_string[500..-1]}" else to_string end end |
#to_hash ⇒ Object
18 19 20 21 22 |
# File 'lib/esplanade/request/raw/body.rb', line 18 def to_hash @hash ||= JSON.parse(to_string.to_s) rescue JSON::ParserError raise BodyIsNotJson.new(**) end |
#to_string ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/esplanade/request/raw/body.rb', line 10 def to_string return @string if @string @string = @env['rack.input'].read @env['rack.input'].rewind @string end |