Files
nairobi/app/models/progress_bar.rb
Javi Martín b911284b86 Update Style/RedundantFreeze rule for Ruby 3.0
In Ruby 3.0, Regexp and Range literals are frozen objects, and so we
don't need to freeze them.
2023-04-13 16:41:15 +02:00

23 lines
672 B
Ruby

class ProgressBar < ApplicationRecord
self.inheritance_column = nil
RANGE = (0..100)
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