Class: Dommy::Rack::FormSubmission

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/rack/form_submission.rb

Overview

Collects successful form controls and resolves the effective method, action, and enctype for a form submission. Stateless given the form, submitter, and session config — it returns a plain data hash and does not make any requests itself.

Constant Summary collapse

FORM_URLENCODED =
"application/x-www-form-urlencoded"
MULTIPART =
"multipart/form-data"
OVERRIDE_METHODS =
%w[PATCH PUT DELETE].freeze

Instance Method Summary collapse

Constructor Details

#initialize(form, submitter, config) ⇒ FormSubmission

Returns a new instance of FormSubmission.



14
15
16
17
18
# File 'lib/dommy/rack/form_submission.rb', line 14

def initialize(form, submitter, config)
  @form = form
  @submitter = submitter
  @config = config
end

Instance Method Details

#submit!Object

Returns { method:, url:, params:, enctype: }.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dommy/rack/form_submission.rb', line 21

def submit!
  method = form_method
  params = collect_params
  method = apply_method_override(method, params)
  params = apply_charset(params)

  {
    method: method,
    url: resolve_action(form_method),
    params: params,
    enctype: form_enctype
  }
end