Module: Pundit::ExpectedAttributeValues::ExpectedAttributesCompat

Defined in:
lib/pundit/expected_attribute_values/expected_attributes_compat.rb

Overview

Provides Pundit 2.6’s expected_attributes on controllers until a released Pundit version includes it. Not used when Pundit::Authorization already defines the method.

Instance Method Summary collapse

Instance Method Details

#expected_attributes(record, action: action_name, param_key: pundit_param_key(record)) ⇒ Object



9
10
11
12
13
# File 'lib/pundit/expected_attribute_values/expected_attributes_compat.rb', line 9

def expected_attributes(record, action: action_name, param_key: pundit_param_key(record))
  policy_instance = policy(record)
  shape = policy_instance.expected_attributes_for_action(action)
  params.expect(param_key => shape)
end

#pundit_param_key(record) ⇒ Object



15
16
17
# File 'lib/pundit/expected_attribute_values/expected_attributes_compat.rb', line 15

def pundit_param_key(record)
  Pundit::PolicyFinder.new(record).param_key
end