Class: PermissionPolicy::Strategies::BaseStrategy
- Inherits:
-
Object
- Object
- PermissionPolicy::Strategies::BaseStrategy
- Defined in:
- lib/permission_policy/strategies/base_strategy.rb
Overview
The base strategy defines the object API for all strategies which can be used for permission checks. Each strategy should inherit from it and implement #match? and #allowed?
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
attributes which are available for #match? and #allowed? are passed from the authorization class.
-
#options ⇒ Object
attributes which are available for #match? and #allowed? are passed from the authorization class.
Instance Method Summary collapse
-
#allowed? ⇒ Boolean
Check if user has necessary permission Has to return true or false.
-
#initialize(authorization, action = nil, options = {}) ⇒ BaseStrategy
constructor
A new instance of BaseStrategy.
-
#match? ⇒ Boolean
Check if the strategy is responsible for handling the permission check Has to return true or false.
Constructor Details
#initialize(authorization, action = nil, options = {}) ⇒ BaseStrategy
Returns a new instance of BaseStrategy.
17 18 19 20 21 22 23 24 25 |
# File 'lib/permission_policy/strategies/base_strategy.rb', line 17 def initialize(, action = nil, = {}) .preconditions.each do |attribute| self.class.send(:attr_accessor, attribute) instance_variable_set(:"@#{attribute}", .public_send(attribute)) end self.action = action self. = end |
Instance Attribute Details
#action ⇒ Object
attributes which are available for #match? and #allowed? are passed from the authorization class.
- precondition_attributes
-
for example [:current_user]
- action
-
This will be :view or :manage
- options
-
A hash having :subject or :feature as keys
15 16 17 |
# File 'lib/permission_policy/strategies/base_strategy.rb', line 15 def action @action end |
#options ⇒ Object
attributes which are available for #match? and #allowed? are passed from the authorization class.
- precondition_attributes
-
for example [:current_user]
- action
-
This will be :view or :manage
- options
-
A hash having :subject or :feature as keys
15 16 17 |
# File 'lib/permission_policy/strategies/base_strategy.rb', line 15 def end |
Instance Method Details
#allowed? ⇒ Boolean
Check if user has necessary permission Has to return true or false
37 38 39 40 41 |
# File 'lib/permission_policy/strategies/base_strategy.rb', line 37 def allowed? raise NotImplementedError, 'please implement #allowed? '\ "for #{self.class.name} which should decide if the action is allowed, "\ 'based on the given attributes' end |
#match? ⇒ Boolean
Check if the strategy is responsible for handling the permission check Has to return true or false
29 30 31 32 33 |
# File 'lib/permission_policy/strategies/base_strategy.rb', line 29 def match? raise NotImplementedError, 'please implement #match? '\ "for #{self.class.name} which should return true or false, "\ 'depending on if it can decide #allowed?' end |