Module: AutoStrongParameters::AutoPermit

Defined in:
lib/auto_strong_parameters/auto_permit.rb

Instance Method Summary collapse

Instance Method Details

#asp_auto_permitted_paramsObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/auto_strong_parameters/auto_permit.rb', line 18

def asp_auto_permitted_params
  if sig = self[AutoStrongParameters.asp_message_key]
    begin
      AutoStrongParameters.verifier.verify(sig)
    rescue => e
      AutoStrongParameters.logger.warn("AutoStrongParameters: Error verifying signature for params: #{e.message}")
      {}
    end
  else
    {}
  end.with_indifferent_access
end

#auto_permit!(key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/auto_strong_parameters/auto_permit.rb', line 5

def auto_permit!(key)
  shape = asp_auto_permitted_params

  permitted_shape = shape[key]

  # Log the shape we're permitting so that developers who may need to use
  # StrongParameters directly can easily copy the shape into a regular
  # #permit call.
  AutoStrongParameters.logger.debug("AutoStrongParameters: Permitting params for key '#{key}' with shape: #{permitted_shape.inspect}")

  require(key).permit(permitted_shape)
end