Module: Granite::Action::Policies
- Extended by:
- ActiveSupport::Concern
- Included in:
- Granite::Action
- Defined in:
- lib/granite/action/policies.rb,
lib/granite/action/policies/any_strategy.rb,
lib/granite/action/policies/always_allow_strategy.rb,
lib/granite/action/policies/required_performer_strategy.rb
Overview
Policies module used for abilities definition. Basically policies are defined as blocks which are executed in action instance context, so performer, object and all the attributes are available inside the block.
By default action is allowed to be performed only by default performer.
Defined Under Namespace
Modules: ClassMethods Classes: AlwaysAllowStrategy, AnyStrategy, RequiredPerformerStrategy
Instance Method Summary collapse
-
#allowed? ⇒ Boolean
Returns true if any of defined policies returns true.
-
#authorize! ⇒ Object
Raises Granite::Action::NotAllowedError if action is not allowed.
- #perform ⇒ Object
- #perform! ⇒ Object
- #try_perform! ⇒ Object
Instance Method Details
#allowed? ⇒ Boolean
Returns true if any of defined policies returns true
75 76 77 78 |
# File 'lib/granite/action/policies.rb', line 75 def allowed? @allowed = _policies_strategy.allowed?(self) unless instance_variable_defined?(:@allowed) @allowed end |
#authorize! ⇒ Object
Raises Granite::Action::NotAllowedError if action is not allowed
82 83 84 85 86 |
# File 'lib/granite/action/policies.rb', line 82 def fail Granite::Action::NotAllowedError, self unless allowed? self end |
#perform ⇒ Object
63 64 65 66 |
# File 'lib/granite/action/policies.rb', line 63 def perform(*, **) super end |
#perform! ⇒ Object
68 69 70 71 |
# File 'lib/granite/action/policies.rb', line 68 def perform!(*, **) super end |
#try_perform! ⇒ Object
58 59 60 61 |
# File 'lib/granite/action/policies.rb', line 58 def try_perform!(*, **) super end |