mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-24 22:23:08 +01:00
10 lines
327 B
Ruby
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
|