Files
nairobi/app/models/progress_bar.rb
taitus ecde8c6439 Add lambda to the validations that use model constants
In this way when we need modify the constants model value in the
model/custom folder, adding lambda it will be possible load the new
values.
2022-03-22 15:52:36 +01:00

23 lines
679 B
Ruby

class ProgressBar < ApplicationRecord
self.inheritance_column = nil
RANGE = (0..100).freeze
enum kind: %i[primary secondary]
belongs_to :progressable, polymorphic: true
translates :title, touch: true
include Globalizable
translation_class_delegate :primary?
validates :progressable, presence: true
validates :kind, presence: true,
uniqueness: {
scope: [:progressable_type, :progressable_id],
conditions: -> { primary }
}
validates :percentage, presence: true, inclusion: { in: ->(*) { RANGE }}, numericality: { only_integer: true }
validates_translation :title, presence: true, unless: :primary?
end