class Swaggable::RackRequestAdapter
Attributes
env[R]
Public Class Methods
new(env)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 6 def initialize env @env = env || raise("env hash is required") end
Public Instance Methods
[](key)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 10 def [] key env[key] end
body()
click to toggle source
# 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()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 48 def content_type env['CONTENT_TYPE'] end
content_type=(value)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 52 def content_type= value env['CONTENT_TYPE'] = value end
parameters(endpoint = endpoint_stub)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 43 def parameters endpoint = endpoint_stub build_path_parameters(endpoint) + build_query_parameters end
parsed_body()
click to toggle source
# 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()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 22 def path env['PATH_INFO'] end
query_parameters()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 14 def query_parameters @query_parameters ||= QueryParams.new env['QUERY_STRING'] end
query_parameters=(p)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 18 def query_parameters= p @query_parameters = QueryParams.new p end
Private Instance Methods
build_path_parameters(endpoint)
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 70 def build_path_parameters endpoint if endpoint endpoint.path_parameters_for(path).map do |name, value| ParameterDefinition.new(name: name, value: value, location: :path) end else [] end end
build_query_parameters()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 64 def build_query_parameters query_parameters.map do |name, value| ParameterDefinition.new(name: name, value: value, location: :query) end end
endpoint_stub()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 80 def endpoint_stub Object.new.tap do |o| def o.path_parameters_for _ {} end end end
rack_request()
click to toggle source
# File lib/swaggable/rack_request_adapter.rb, line 60 def rack_request @rack_request = Rack::Request.new env end