Class: ActiveModel::FormObject::StrongParameters::StrongParameters
- Inherits:
-
Object
- Object
- ActiveModel::FormObject::StrongParameters::StrongParameters
- Defined in:
- lib/active_model/form_object/strong_parameters.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass) ⇒ StrongParameters
constructor
A new instance of StrongParameters.
- #set(parameter_name, opts) ⇒ Object
Constructor Details
#initialize(klass) ⇒ StrongParameters
Returns a new instance of StrongParameters.
24 25 26 |
# File 'lib/active_model/form_object/strong_parameters.rb', line 24 def initialize(klass) @klass = klass end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
22 23 24 |
# File 'lib/active_model/form_object/strong_parameters.rb', line 22 def klass @klass end |
Instance Method Details
#set(parameter_name, opts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_model/form_object/strong_parameters.rb', line 28 def set(parameter_name, opts) opts.each do |key, value| klass.send(:define_method, "#{key}_params".to_sym) do params = self.send(parameter_name) unless params[key].nil? self.unpermitted_attrs ||= {} unpermitted = params[key].keys.map(&:to_s) - value.map(&:to_s) self.unpermitted_attrs[key] = unpermitted if unpermitted.any? end params.require(key).permit(value) end end end |