Module: Critic::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/critic/controller.rb
Overview
Sugar for accessing the authorization interface
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
Instance Method Summary collapse
- #authorize(resource, action = default_action, policy: policy(resource), with: nil) ⇒ Object
- #authorize_scope(scope, *args, action: nil, policy: policy(scope), **options) ⇒ Object
- #authorized?(resource, *args, **options) ⇒ Boolean
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
37 38 39 |
# File 'lib/critic/controller.rb', line 37 def @authorization end |
Instance Method Details
#authorize(resource, action = default_action, policy: policy(resource), with: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/critic/controller.rb', line 13 def (resource, action = default_action, policy: policy(resource), with: nil) args = [with] if !with.is_a?(Array) && !with.nil? @authorization = policy.(action, critic, resource, args) if @authorization.denied? @authorization.result end |
#authorize_scope(scope, *args, action: nil, policy: policy(scope), **options) ⇒ Object
31 32 33 34 35 |
# File 'lib/critic/controller.rb', line 31 def (scope, *args, action: nil, policy: policy(scope), **) = action || policy.scope (scope, , *args, policy: policy, **) end |
#authorized?(resource, *args, **options) ⇒ Boolean
25 26 27 28 29 |
# File 'lib/critic/controller.rb', line 25 def (resource, *args, **) (resource, *args, **) rescue Critic::AuthorizationDenied false end |