Class: Hyrax::Forms::FailedSubmissionFormWrapper Deprecated

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/forms/hyrax/forms/failed_submission_form_wrapper.rb

Overview

Deprecated.

This class should be removed when we switch to Valkyrie::ChangeSet instead of Hydra::Forms.

This object is responsible for exposing the user submitted params from a failed POST/PUT/PATCH.

Instance Method Summary collapse

Constructor Details

#initialize(form:, input_params:, permitted_params: nil) ⇒ FailedSubmissionFormWrapper

Returns a new instance of FailedSubmissionFormWrapper.

Parameters:

  • form
  • input_params (ActionController::Parameters)
  • permitted_params (Hash) (defaults to: nil)

    this likely comes from a class method on the given form. It’s used for enforcing strong parameters. It’s more of a schema for what the input parameters should be. Why not rely on the form.class.permitted_params? This is a violation of the Law of Demeter, and due to object delegation, the form.class may be a delegate class, and not the one that has permitted_params.

See Also:

  • WorkForm.build_permitted_params


25
26
27
28
29
30
31
32
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 25

def initialize(form:, input_params:, permitted_params: nil)
  @form = form
  super(@form)
  @input_params = input_params
  @exposed_params = {}
  @permitted_params = permitted_params || __default_permitted_params__(form: form)
  build_exposed_params!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



69
70
71
72
73
74
75
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 69

def method_missing(method_name, *args, &block)
  if @exposed_params.key?(method_name)
    @exposed_params.fetch(method_name)
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



59
60
61
62
63
64
65
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 59

def [](key)
  if @exposed_params.key?(key)
    @exposed_params.fetch(key)
  else
    super
  end
end

#classObject

Yes, I don’t want to delegate class to the form, but based on past experiences, there are times where SimpleForm requests class.model_name and that had better align with the underlying form.

Upon testing, when I don’t have this method, the Javascript for “Requirements” on the new form will not properly acknowledge that we have re-filled the HTML form with the submitted non-file fields.



43
44
45
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 43

def class
  @form.class
end

#inspectObject



55
56
57
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 55

def inspect
  "Hyrax::Forms::FailedSubmissionFormWrapper(#{@form})"
end

#model_nameObject



47
48
49
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 47

def model_name
  @form.model_name
end

#to_modelObject



51
52
53
# File 'app/forms/hyrax/forms/failed_submission_form_wrapper.rb', line 51

def to_model
  self
end