retrospring/app/validators/read_only_validator.rb
2025-02-21 23:25:22 +01:00

10 lines
327 B
Ruby

# frozen_string_literal: true
class ReadOnlyValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless Retrospring::Config.readonly?
return if value == record.public_send(:"#{attribute}_was")
record.errors.add(attribute, message: I18n.t("errors.read_only_mode"))
end
end