Class: Admission::Tests::Evaluation
- Inherits:
-
Object
- Object
- Admission::Tests::Evaluation
- Defined in:
- lib/admission/tests/tests.rb
Instance Attribute Summary collapse
-
#arbitration ⇒ Object
readonly
Returns the value of attribute arbitration.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #evaluate(privilege) ⇒ Object
- #evaluate_groups(to_assert, to_refute) ⇒ Object
- #for_request(name) ⇒ Object
-
#initialize(status, scope) ⇒ Evaluation
constructor
A new instance of Evaluation.
- #messages_for_groups(should, should_not) ⇒ Object
- #request=(name) ⇒ Object
Constructor Details
#initialize(status, scope) ⇒ Evaluation
Returns a new instance of Evaluation.
57 58 59 60 |
# File 'lib/admission/tests/tests.rb', line 57 def initialize status, scope @status = status @scope = scope end |
Instance Attribute Details
#arbitration ⇒ Object (readonly)
Returns the value of attribute arbitration.
55 56 57 |
# File 'lib/admission/tests/tests.rb', line 55 def arbitration @arbitration end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
55 56 57 |
# File 'lib/admission/tests/tests.rb', line 55 def status @status end |
Instance Method Details
#evaluate(privilege) ⇒ Object
71 72 73 74 |
# File 'lib/admission/tests/tests.rb', line 71 def evaluate privilege arbitration.prepare_sitting privilege.context arbitration.rule_per_privilege(privilege).eql?(true) end |
#evaluate_groups(to_assert, to_refute) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/admission/tests/tests.rb', line 76 def evaluate_groups to_assert, to_refute to_assert = to_assert.map{|p| ContextSpecificPrivilege.new p} to_refute = to_refute.map{|p| ContextSpecificPrivilege.new p} sorted = (to_assert + to_refute).sort_by{|p| p.privilege.context} admissible, denied = sorted.partition{|p| evaluate p.privilege} [ (denied - to_refute), (admissible - to_assert) ] end |
#for_request(name) ⇒ Object
66 67 68 69 |
# File 'lib/admission/tests/tests.rb', line 66 def for_request name self.request = name self end |
#messages_for_groups(should, should_not) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/admission/tests/tests.rb', line 88 def should, should_not [ should.map{|p| Admission::Tests. arbitration, p.privilege}, should_not.map{|p| Admission::Tests. arbitration, p.privilege} ].flatten end |
#request=(name) ⇒ Object
62 63 64 |
# File 'lib/admission/tests/tests.rb', line 62 def request= name @arbitration = status.instantiate_arbitration name.to_sym, @scope end |