Module: ActionPolicy::Behaviours::Scoping
- Included in:
- ActionPolicy::Behaviour, Policy::Scoping
- Defined in:
- lib/action_policy/behaviours/scoping.rb
Overview
Adds ‘authorized_scop` method to behaviour
Instance Method Summary collapse
-
#authorization_scope_type_for(policy, target) ⇒ Object
Infer scope type for target if none provided.
-
#authorized_scope(target, type: nil, as: :default, scope_options: nil, **options) ⇒ Object
(also: #authorized)
Apply scope to the target of the specified type.
Instance Method Details
#authorization_scope_type_for(policy, target) ⇒ Object
Infer scope type for target if none provided. Raises an exception if type couldn’t be inferred.
30 31 32 |
# File 'lib/action_policy/behaviours/scoping.rb', line 30 def (policy, target) policy.resolve_scope_type(target) end |
#authorized_scope(target, type: nil, as: :default, scope_options: nil, **options) ⇒ Object Also known as:
Apply scope to the target of the specified type.
NOTE: policy lookup consists of the following steps:
- first, check whether `with` option is present
- secondly, try to infer policy class from `target` (non-raising lookup)
- use `implicit_authorization_target` if none of the above works.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_policy/behaviours/scoping.rb', line 13 def (target, type: nil, as: :default, scope_options: nil, **) [:context] && ([:context] = .merge([:context])) policy = policy_for(record: target, allow_nil: true, **) policy ||= policy_for(record: , **) type ||= (policy, target) name = as Authorizer.scopify(target, policy, type:, name:, scope_options:) end |