Class: Committee::Test::ExceptParameter::BodyHandler
- Inherits:
-
Object
- Object
- Committee::Test::ExceptParameter::BodyHandler
- Includes:
- StringDummyLookup
- Defined in:
- lib/committee/test/except_parameter.rb
Overview
Handler for request body parameters
Supports three content types:
-
application/json (and variants): replaces rack.input stream so that request_unpack re-parses the modified body during validation.
-
application/x-www-form-urlencoded / multipart/form-data: pre-populates rack.request.form_hash, which Rack returns directly from request.POST without re-parsing the raw body.
-
Other content types (e.g. binary): no-op, as RequestUnpacker does not extract named parameters from them.
Instance Method Summary collapse
-
#apply(param_names) ⇒ void
Apply dummy values to body parameters based on content type.
-
#initialize(request, committee_options) ⇒ BodyHandler
constructor
A new instance of BodyHandler.
-
#restore ⇒ void
Restore original body content.
Constructor Details
#initialize(request, committee_options) ⇒ BodyHandler
Returns a new instance of BodyHandler.
232 233 234 235 236 237 |
# File 'lib/committee/test/except_parameter.rb', line 232 def initialize(request, ) @request = request @committee_options = @original_body = nil @original_form_values = nil end |
Instance Method Details
#apply(param_names) ⇒ void
This method returns an undefined value.
Apply dummy values to body parameters based on content type.
242 243 244 245 246 247 248 249 |
# File 'lib/committee/test/except_parameter.rb', line 242 def apply(param_names) if json_content_type? apply_json(param_names) elsif form_content_type? apply_form(param_names) end # Other content types: no-op end |
#restore ⇒ void
This method returns an undefined value.
Restore original body content
253 254 255 256 |
# File 'lib/committee/test/except_parameter.rb', line 253 def restore restore_json if @original_body restore_form if @original_form_values end |