Class: Committee::Test::ExceptParameter::BodyHandler

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(request, committee_options) ⇒ BodyHandler

Returns a new instance of BodyHandler.

Parameters:

  • request (Rack::Request)

    The request object

  • committee_options (Hash)

    Committee options hash



232
233
234
235
236
237
# File 'lib/committee/test/except_parameter.rb', line 232

def initialize(request, committee_options)
  @request = request
  @committee_options = 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.

Parameters:

  • param_names (Array<String, Symbol>)

    Body parameter names to except



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

#restorevoid

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