Class: Rddd::Authorization::Rule
- Inherits:
-
Object
- Object
- Rddd::Authorization::Rule
- Defined in:
- lib/rddd/authorization/rule.rb
Overview
Representation of single authorization rule. It applies to a specific action and evaluates the given block to decide the outcome.
Constant Summary collapse
- InvalidEvaluationBlock =
Class.new(RuntimeError)
Instance Method Summary collapse
-
#can?(user, params) ⇒ Boolean
Evalute the rule for a given user and params.
-
#initialize(action, &block) ⇒ Rule
constructor
Initialize.
-
#is_for?(action) ⇒ Boolean
Is the Rule for given action?.
Constructor Details
#initialize(action, &block) ⇒ Rule
Initialize.
17 18 19 20 21 22 23 |
# File 'lib/rddd/authorization/rule.rb', line 17 def initialize(action, &block) # Block should take two arguments - user and params. raise InvalidEvaluationBlock unless block.arity == 2 @action = action @block = block end |
Instance Method Details
#can?(user, params) ⇒ Boolean
Evalute the rule for a given user and params.
41 42 43 |
# File 'lib/rddd/authorization/rule.rb', line 41 def can?(user, params) @block.call(user, params) end |
#is_for?(action) ⇒ Boolean
Is the Rule for given action?
31 32 33 |
# File 'lib/rddd/authorization/rule.rb', line 31 def is_for?(action) @action == action end |