retrospring/app/validators/read_only_validator.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

11 lines
327 B
Ruby
Raw Normal View History

2025-02-21 17:18:03 +01:00
# 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