In rubocop-rails 2.26.0, support was added for Rails 7 syntax in the Rails/EnumHash rule. We took this opportunity to ensure consistency by converting all enums to hash with integer values. This format minimizes the risk of data consistency issues in the database when adding new values.
26 lines
744 B
Ruby
26 lines
744 B
Ruby
class ProgressBar < ApplicationRecord
|
|
self.inheritance_column = nil
|
|
RANGE = (0..100)
|
|
|
|
enum :kind, { primary: 0, secondary: 1 }
|
|
|
|
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
|