Class: ActionAuthorization::Resource
- Inherits:
-
Object
- Object
- ActionAuthorization::Resource
- Defined in:
- lib/authorizer/resource.rb
Overview
This class represents a generic list of models that are about to authorized.
It is instantiated automatically by ActionController::Metal#check_authorization and there should be little need to instantiate it directly.
Instance Attribute Summary collapse
-
#action ⇒ String, Symbol
readonly
The action which
:actoris attempting to complete. -
#actor ⇒ Model
readonly
The model attempting authorization (usually a
User). -
#options ⇒ Object
readonly
The options which are being used for authorization.
-
#resources ⇒ Object
readonly
The list of models being authorized.
Instance Method Summary collapse
-
#get ⇒ Object
Returns the list of models passed into the constructor if the list passes authorization, otherwise raises
ForbiddenError. -
#initialize(action, actor, *resources, **options) ⇒ Resource
constructor
Creates a new instance of
Resource.
Constructor Details
#initialize(action, actor, *resources, **options) ⇒ Resource
Creates a new instance of Resource.
30 31 32 33 34 35 |
# File 'lib/authorizer/resource.rb', line 30 def initialize(action, actor, *resources, **) @action = action @actor = actor @resources = resources @options = end |
Instance Attribute Details
#action ⇒ String, Symbol (readonly)
Returns The action which :actor is attempting to complete.
12 13 14 |
# File 'lib/authorizer/resource.rb', line 12 def action @action end |
#actor ⇒ Model (readonly)
Returns The model attempting authorization (usually a User).
15 16 17 |
# File 'lib/authorizer/resource.rb', line 15 def actor @actor end |
#options ⇒ Object (readonly)
Returns The options which are being used for authorization.
21 22 23 |
# File 'lib/authorizer/resource.rb', line 21 def @options end |
#resources ⇒ Object (readonly)
Returns The list of models being authorized.
18 19 20 |
# File 'lib/authorizer/resource.rb', line 18 def resources @resources end |
Instance Method Details
#get ⇒ Object
Returns the list of models passed into the constructor if the list passes authorization, otherwise raises ForbiddenError.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/authorizer/resource.rb', line 42 def get return @resources if @resources.nil? return @resources if @resources.length == 0 behavior = @options[:behavior] if !behavior behavior = :filter end case behavior when :allow_all collect_permitted(return_res: true) {|results| results.length > 0} when :deny_all collect_permitted {|results| results.length == @resources.length} when :filter collect_permitted {|results| results.length > 0} else collect_permitted {|results| results.length > 0} end end |