Class: ExamRegistration::AuthorizationCriterion

Inherits:
Object
  • Object
show all
Defined in:
app/models/exam_registration/authorization_criterion.rb

Direct Known Subclasses

None, PassedExercises

Defined Under Namespace

Classes: None, PassedExercises

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AuthorizationCriterion

Returns a new instance of AuthorizationCriterion.



4
5
6
# File 'app/models/exam_registration/authorization_criterion.rb', line 4

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



2
3
4
# File 'app/models/exam_registration/authorization_criterion.rb', line 2

def value
  @value
end

Class Method Details

.parse(type, value) ⇒ Object



28
29
30
# File 'app/models/exam_registration/authorization_criterion.rb', line 28

def self.parse(type, value)
  parse_criterion_type(type, value)
end

.parse_criterion_type(type, value) ⇒ Object



32
33
34
35
36
# File 'app/models/exam_registration/authorization_criterion.rb', line 32

def self.parse_criterion_type(type, value)
  "ExamRegistration::AuthorizationCriterion::#{type.camelize}".constantize.new(value)
rescue
  raise "Invalid criterion type #{type}"
end

Instance Method Details

#as_jsonObject



12
13
14
# File 'app/models/exam_registration/authorization_criterion.rb', line 12

def as_json
  { type: type, value: value }
end

#authorization_criteria_matcherObject



42
43
44
# File 'app/models/exam_registration/authorization_criterion.rb', line 42

def authorization_criteria_matcher
  criterion_matcher
end

#authorization_status_for(authorization_request) ⇒ Object



24
25
26
# File 'app/models/exam_registration/authorization_criterion.rb', line 24

def authorization_status_for(authorization_request)
  meets_authorization_criteria?(authorization_request) ? :approved : :rejected
end

#ensure_valid!Object



16
17
18
# File 'app/models/exam_registration/authorization_criterion.rb', line 16

def ensure_valid!
  raise "Invalid criterion value #{value} for #{type}" unless valid?
end

#meets_authorization_criteria?(authorization_request) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/exam_registration/authorization_criterion.rb', line 38

def meets_authorization_criteria?(authorization_request)
  meets_criterion? authorization_request.user, authorization_request.organization
end

#process_request!(authorization_request) ⇒ Object



20
21
22
# File 'app/models/exam_registration/authorization_criterion.rb', line 20

def process_request!(authorization_request)
  authorization_request.update! status: authorization_status_for(authorization_request)
end

#typeObject



8
9
10
# File 'app/models/exam_registration/authorization_criterion.rb', line 8

def type
  self.class.name.demodulize.underscore
end