Module: Pundit::ExpectedAttributeValues::ValueResolver
- Defined in:
- lib/pundit/expected_attribute_values/value_resolver.rb
Class Method Summary collapse
- .normalize_list(values) ⇒ Object
- .normalize_value(value) ⇒ Object
- .resolve(source, policy) ⇒ Object
- .resolve_hash_for_action(policy, action) ⇒ Object
Class Method Details
.normalize_list(values) ⇒ Object
32 33 34 |
# File 'lib/pundit/expected_attribute_values/value_resolver.rb', line 32 def normalize_list(values) Array(values).map { |v| normalize_value(v) } end |
.normalize_value(value) ⇒ Object
36 37 38 39 40 |
# File 'lib/pundit/expected_attribute_values/value_resolver.rb', line 36 def normalize_value(value) return value.to_sym if ExpectedAttributeValues.symbolize_values && value.respond_to?(:to_sym) value.is_a?(Symbol) ? value.to_s : value end |
.resolve(source, policy) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pundit/expected_attribute_values/value_resolver.rb', line 8 def resolve(source, policy) case source when Proc policy.instance_exec(&source) when Symbol policy.public_send(source) else source end end |
.resolve_hash_for_action(policy, action) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pundit/expected_attribute_values/value_resolver.rb', line 19 def resolve_hash_for_action(policy, action) action_method = "expected_attribute_values_for_#{action}" if policy.respond_to?(action_method, true) policy.public_send(action_method) || {} elsif policy.respond_to?(:expected_attribute_values_for_action, true) policy.expected_attribute_values_for_action(action) || {} elsif policy.respond_to?(:expected_attribute_values, true) policy.expected_attribute_values || {} else {} end end |