Class: Committee::RequestUnpacker
- Inherits:
-
Object
- Object
- Committee::RequestUnpacker
- Defined in:
- lib/committee/request_unpacker.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(request, options = {}) ⇒ RequestUnpacker
constructor
A new instance of RequestUnpacker.
Constructor Details
#initialize(request, options = {}) ⇒ RequestUnpacker
Returns a new instance of RequestUnpacker.
3 4 5 6 7 8 9 |
# File 'lib/committee/request_unpacker.rb', line 3 def initialize(request, ={}) @request = request @allow_form_params = [:allow_form_params] @allow_query_params = [:allow_query_params] @optimistic_json = [:optimistic_json] end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/committee/request_unpacker.rb', line 11 def call # if Content-Type is empty or JSON, and there was a request body, try to # interpret it as JSON params = if !@request.content_type || @request.content_type =~ %r{application/json} parse_json elsif @optimistic_json parse_json rescue MultiJson::LoadError nil end params = if params params elsif @allow_form_params && @request.content_type == "application/x-www-form-urlencoded" # Actually, POST means anything in the request body, could be from # PUT or PATCH too. Silly Rack. indifferent_params(@request.POST) else {} end if @allow_query_params indifferent_params(@request.GET).merge(params) else params end end |