Class: Swaggable::RackRequestAdapter
- Inherits:
-
Object
- Object
- Swaggable::RackRequestAdapter
- Defined in:
- lib/swaggable/rack_request_adapter.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #body ⇒ Object
- #content_type ⇒ Object
- #content_type=(value) ⇒ Object
-
#initialize(env) ⇒ RackRequestAdapter
constructor
A new instance of RackRequestAdapter.
- #parameters(endpoint = endpoint_stub) ⇒ Object
- #parsed_body ⇒ Object
- #path ⇒ Object
- #query_parameters ⇒ Object
- #query_parameters=(p) ⇒ Object
Constructor Details
#initialize(env) ⇒ RackRequestAdapter
Returns a new instance of RackRequestAdapter.
6 7 8 |
# File 'lib/swaggable/rack_request_adapter.rb', line 6 def initialize env @env = env || raise("env hash is required") end |
Instance Method Details
#[](key) ⇒ Object
10 11 12 |
# File 'lib/swaggable/rack_request_adapter.rb', line 10 def [] key env[key] end |
#body ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/swaggable/rack_request_adapter.rb', line 26 def body @body ||= if stream = env['rack.input'] string = stream.read string == '' ? nil : string else nil end end |
#content_type ⇒ Object
48 49 50 |
# File 'lib/swaggable/rack_request_adapter.rb', line 48 def content_type env['CONTENT_TYPE'] end |
#content_type=(value) ⇒ Object
52 53 54 |
# File 'lib/swaggable/rack_request_adapter.rb', line 52 def content_type= value env['CONTENT_TYPE'] = value end |
#parameters(endpoint = endpoint_stub) ⇒ Object
43 44 45 46 |
# File 'lib/swaggable/rack_request_adapter.rb', line 43 def parameters endpoint = endpoint_stub build_path_parameters(endpoint) + build_query_parameters end |
#parsed_body ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/swaggable/rack_request_adapter.rb', line 35 def parsed_body case content_type when 'application/json' then JSON.parse body else raise "Don't know how to parse #{env['CONTENT_TYPE'].inspect}" end end |
#path ⇒ Object
22 23 24 |
# File 'lib/swaggable/rack_request_adapter.rb', line 22 def path env['PATH_INFO'] end |
#query_parameters ⇒ Object
14 15 16 |
# File 'lib/swaggable/rack_request_adapter.rb', line 14 def query_parameters @query_parameters ||= QueryParams.new env['QUERY_STRING'] end |
#query_parameters=(p) ⇒ Object
18 19 20 |
# File 'lib/swaggable/rack_request_adapter.rb', line 18 def query_parameters= p @query_parameters = QueryParams.new p end |