2023-05-25 19:09:59 +02:00
|
|
|
class SVASVRConfiguration
|
|
|
|
include ActiveModel::Model
|
|
|
|
include ActiveModel::Attributes
|
|
|
|
|
|
|
|
attribute :decision, default: 'disabled'
|
|
|
|
attribute :period, default: 2
|
|
|
|
attribute :unit, default: 'months'
|
|
|
|
attribute :resume, default: 'continue'
|
|
|
|
|
|
|
|
DECISION_OPTIONS = ['disabled', 'sva', 'svr']
|
|
|
|
UNIT_OPTIONS = ['days', 'weeks', 'months']
|
|
|
|
RESUME_OPTIONS = ['continue', 'reset']
|
|
|
|
|
2023-06-21 12:37:21 +02:00
|
|
|
validates :decision, inclusion: { in: DECISION_OPTIONS.without('svr') }
|
2023-05-25 19:09:59 +02:00
|
|
|
validates :period, presence: true, numericality: { only_integer: true }, if: -> { enabled? }
|
|
|
|
validates :unit, presence: true, inclusion: { in: UNIT_OPTIONS }, if: -> { enabled? }
|
|
|
|
validates :resume, presence: true, inclusion: { in: RESUME_OPTIONS }, if: -> { enabled? }
|
|
|
|
|
|
|
|
def self.unit_options
|
|
|
|
UNIT_OPTIONS
|
|
|
|
end
|
|
|
|
|
2023-06-22 12:06:38 +02:00
|
|
|
def human_decision
|
|
|
|
return if decision == 'disabled'
|
|
|
|
|
|
|
|
decision.upcase
|
|
|
|
end
|
|
|
|
|
2023-05-25 19:09:59 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def enabled?
|
|
|
|
decision != 'disabled'
|
|
|
|
end
|
|
|
|
end
|