Sha256: 66dfdb539711e2a0fb35afaa7658ace58fbb4b70cc1e55613690f41eeba7d307
Contents?: true
Size: 1.42 KB
Versions: 25
Compression:
Stored size: 1.42 KB
Contents
class ExamRegistration::AuthorizationCriterion attr_reader :value def initialize(value) @value = value end def type self.class.name.demodulize.underscore end def as_json { type: type, value: value } end def ensure_valid! raise "Invalid criterion value #{value} for #{type}" unless valid? end def process_request!(authorization_request) authorization_request.update! status: authorization_status_for(authorization_request) end def authorization_status_for(authorization_request) meets_authorization_criteria?(authorization_request) ? :approved : :rejected end def self.parse(type, value) parse_criterion_type(type, value) end def self.parse_criterion_type(type, value) "ExamRegistration::AuthorizationCriterion::#{type.camelize}".constantize.new(value) rescue raise "Invalid criterion type #{type}" end end class ExamRegistration::AuthorizationCriterion::None < ExamRegistration::AuthorizationCriterion def initialize(_) @value = nil end def valid? !value end def meets_authorization_criteria?(_authorization_request) true end end class ExamRegistration::AuthorizationCriterion::PassedExercises < ExamRegistration::AuthorizationCriterion def valid? value.positive? end def meets_authorization_criteria?(authorization_request) authorization_request.user.passed_submissions_count_in(authorization_request.organization) >= value end end
Version data entries
25 entries across 25 versions & 1 rubygems