Class: Admission::Tests::Evaluation

Inherits:
Object
  • Object
show all
Defined in:
lib/admission/tests/tests.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arbitrationObject (readonly)

Returns the value of attribute arbitration.



55
56
57
# File 'lib/admission/tests/tests.rb', line 55

def arbitration
  @arbitration
end

#statusObject (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 messages_for_groups should, should_not
  [
      should.map{|p| Admission::Tests.assertion_failed_message arbitration, p.privilege},
      should_not.map{|p| Admission::Tests.refutation_failed_message 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