demarches-normaliennes/app/models/sva_svr_configuration.rb

35 lines
911 B
Ruby
Raw Normal View History

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']
validates :decision, inclusion: { in: DECISION_OPTIONS }
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
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