Class: CanTango::PermissionEngine::Evaluator
- Inherits:
-
Object
- Object
- CanTango::PermissionEngine::Evaluator
- Includes:
- Helpers::Debug, Rules
- Defined in:
- lib/cantango/permission_engine/evaluator.rb
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
Returns the value of attribute ability.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #evaluate!(user) ⇒ Object
-
#initialize(ability, rule) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #rules ⇒ Object
- #safe_rules! ⇒ Object
- #user ⇒ Object
Methods included from Rules::Dsl
Methods included from Helpers::Debug
Constructor Details
#initialize(ability, rule) ⇒ Evaluator
Returns a new instance of Evaluator.
10 11 12 13 14 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 10 def initialize ability, rule @ability = ability @rule = rule safe_rules! end |
Instance Attribute Details
#ability ⇒ Object (readonly)
Returns the value of attribute ability.
6 7 8 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 6 def ability @ability end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
6 7 8 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 6 def rule @rule end |
Instance Method Details
#evaluate!(user) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 16 def evaluate! user debug "Evaluating rule:" debug rule.can debug rule.cannot @user = user instance_eval rule.can if rule.can? instance_eval rule.cannot if rule.cannot? end |
#rules ⇒ Object
25 26 27 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 25 def rules ability.send :rules end |
#safe_rules! ⇒ Object
33 34 35 36 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 33 def safe_rules! rule.can.gsub!(/(User|UserAccount)/,'::\1') if rule.can? rule.cannot.gsub!(/(User|UserAccount)/,'::\1') if rule.cannot? end |
#user ⇒ Object
29 30 31 |
# File 'lib/cantango/permission_engine/evaluator.rb', line 29 def user @user end |