Note we're excluding a few files: * Configuration files that weren't generated by us * Migration files that weren't generated by us * The Gemfile, since it includes an important comment that must be on the same line as the gem declaration * The Budget::Stats class, since the heading statistics are a mess and having shorter lines would require a lot of refactoring
26 lines
736 B
Ruby
26 lines
736 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
|