demarches-normaliennes/app/models/sva_svr_configuration.rb
2023-07-11 10:01:45 +02:00

28 lines
825 B
Ruby

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']
validates :decision, inclusion: { in: DECISION_OPTIONS }
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
private
def enabled?
decision != 'disabled'
end
end